How to fix Django NotperlyConfigured exception?

I followed Django installations using pip in virtualenv since I am learning Django. When I wrote this in a Python shell in a Django book,

from django import template t = template.Template("My name is {{ name }}.") 

I have this exception. I do not know how to solve this.

 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "django/template/base.py", line 123, in __init__ if settings.TEMPLATE_DEBUG and origin is None: File "django/conf/__init__.py", line 53, in __getattr__ self._setup(name) File "django/conf/__init__.py", line 46, in _setup % (desc, ENVIRONMENT_VARIABLE)) django.core.exceptions.ImproperlyConfigured: Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. 

Can someone pass me? I am using Mac OS X 10.8

+6
source share
3 answers

It seems that you are using the python shell with the python command. Therefore, the DJANGO_SETTINGS_MODULE variable DJANGO_SETTINGS_MODULE not available. Launch your python application shell with

 python manage.py shell 

Learn more about manage.py .

manage.py sets the DJANGO_SETTINGS_MODULE environment variable to point to your settings.py project file.

+18
source

you need to run the django shell so that it loads the settings

 python manage.py shell 
+4
source

Django needs your application settings. Since it is already inside your manage.py, just run:

python manage.py shell

This should solve the problem quickly enough.

0
source

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


All Articles