Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running Kubuntu 12.04 LTS.

I have been reading the django book and I have hit a snag where I'm unable to set up posgresql to work with the django app.

I have installed both python-postgresql and python-psycopg via synaptic. When I run: import conncetion from django.db I get the following error:

Traceback (most recent call last):                                                                                                          
  File "<stdin>", line 1, in <module>                                                                                                       
  File "/usr/local/lib/python2.7/dist-packages/django/db/", line 11, in <module>                                                 
    if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:                                                                   
  File "/usr/local/lib/python2.7/dist-packages/django/conf/", line 53, in __getattr__                                            
  File "/usr/local/lib/python2.7/dist-packages/django/conf/", line 46, in _setup                                                 
% (desc, ENVIRONMENT_VARIABLE))                                                                                                         
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the envirogs.configure() before accessing settings.  

Help me understand how django and postgreql communicate or direct me to a django tutorial suited for beginners or a post that helps one set up django and posgre on ubuntu.

share|improve this question

You need to provide details in This is the part which you have to configure

    'default': {
        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.

Please refer


This is your file with out the comments.

    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2'
        'NAME': 'blank_db',
        'USER': 'postgres',
        'PASSWORD': 'thepasswd',
        'HOST': '',
        'PORT': '',

You are missing a comma at the end of ENGINE entry

share|improve this answer
I think it's looking for in the wrong place. I have my databases part well configured. here it is:… – urbanslug Jun 16 '13 at 12:01
What is your folder structure? – thefourtheye Jun 16 '13 at 12:15
The one you get when you run startproject mysite.. If I uninstalled and re-isntalled django would that fix it? – urbanslug Jun 16 '13 at 12:49
Updated my answer. Please check that – thefourtheye Jun 16 '13 at 13:10
what should be in the file? I cd'd into djcode code where there is and ran python then I ran from django.db import connection and then cursor = connection.cursor. All without errors. So I assume it worked. The key was to work from the directory with file. Thanks that helped. – urbanslug Jun 16 '13 at 14:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.