[Django] Error issues collection
Nov 7, 2021
django.core.exceptions.ImproperlyConfigured: Requested setting XXX, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
- According to the official document like below. If your script out of control from django, should tell django which setting you are using.
DJANGO_SETTINGS_MODULEWhen you use Django, you have to tell it which settings you’re using. Do this by using an environment variable, DJANGO_SETTINGS_MODULE.The value of DJANGO_SETTINGS_MODULE should be in Python path syntax, e.g. mysite.settings. Note that the settings module should be on the Python import search path.
- Setup the environment in your script, then you could use your django related resources.
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
'RealEstateProject.settings')