This error is easy to reproduce. Basically just start a new django project and run the server with django-admin. I read many StackOverflow posts and tried multiple methods but did not work. Here are the detailed steps to reproduce:
- Created new directory named
testproject
pipenv install django
- Started new project named
test
with the django start project script pipenv shell
django-admin runserver
- Error:
"django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings."
- Typed this in ubuntu as suggested in the official django docs:
export DJANGO_SETTINGS_MODULE=test.settings
django-admin runserver
- Got a giant line of error followed by
ModuleNotFoundError: No module named 'test'
. However, if i dodjango-admin runserver --pythonpath=. --settings="test.settings"
the server successfully runs.
I know I can just use python manage.py to start the server but my project uses Django cache framework and when I try to access the cache the same settings are not configured
error is thrown. Trying to understand what is going on, any help would be greatly appreciated.