Django settings not configured

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

As described here, I opened the python shell and tried to import the project, for example:

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 do not understand the error message very well. Where exactly is DJANGO_SETTINGS_MODULE defined or call settings.configure() ?

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

+5
source share
1 answer

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

Or open the Django shell through django-admin setting the environment variable first:

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

See also:

+5
source

Source: https://habr.com/ru/post/1246339/


All Articles