Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django settings not configured error

Tags:

python

django

I am doing the Django introductory tutorial from here: https://docs.djangoproject.com/en/1.9/intro/tutorial05/

As described there, I opened the python shell and tried to import the project, like this:

from polls.models import Question

However, I get this error:

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

I don't understand the error message very well. Where exactly should I define DJANGO_SETTINGS_MODULE or call settings.configure() ?

If I try to open the django shell, I get the same message.

like image 514
octavian Avatar asked Apr 03 '16 14:04

octavian


1 Answers

Run python manage.py shell from the root of your project - it automatically sets the environment variable pointing to your project settings.

Or, open the Django shell via django-admin setting the environment variable beforehand:

$ export DJANGO_SETTINGS_MODULE="myproj.settings"
$ django-admin shell  # requires the DJANGO_SETTINGS_MODULE to be set

Also see:

  • When should you use django-admin.py verus manage.py?
like image 115
alecxe Avatar answered Oct 06 '22 20:10

alecxe