Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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/__init__.py", 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/__init__.py", line 53, in __getattr__                                            
    self._setup(name)                                                                                                                       
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", 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

1 Answer 1

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

DATABASES = {
    '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 http://www.djangobook.com/en/2.0/chapter05.html#configuring-the-database

EDIT:

This is your settings.py file with out the comments.

DATABASES = {
    '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 settings.py in the wrong place. I have my databases part well configured. here it is: docs.google.com/file/d/0B3l4n8Q6GpBOS0VZRTRJdjFOczg/… –  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 django-admin.py 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
1  
what should be in the new.py file? I cd'd into djcode code where there is manage.py 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 manage.py file. Thanks that helped. –  urbanslug Jun 16 '13 at 14:04

Your Answer

 
discard

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.