0

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:

  1. Created new directory named testproject
  2. pipenv install django
  3. Started new project named test with the django start project script
  4. pipenv shell
  5. django-admin runserver
  6. 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."
  7. Typed this in ubuntu as suggested in the official django docs: export DJANGO_SETTINGS_MODULE=test.settings
  8. django-admin runserver
  9. Got a giant line of error followed by ModuleNotFoundError: No module named 'test'. However, if i do django-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.

  • 1
    Have you tried `python manage.py runserver`? – Klaus D. Nov 24 '19 at 06:06
  • 1
    Export pythonpath solved the issue: https://stackoverflow.com/questions/8826534/how-can-i-correctly-set-django-settings-module-for-my-django-project-i-am-using – Daniel Yang Nov 24 '19 at 06:12
  • 1
    @Klaus D. Yes i did and it worked, but I think that's because in manage.py the env var is set for me: ```os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test.settings')``` – Daniel Yang Nov 24 '19 at 06:14
  • 1
    Just to make it clear: you should use `manage.py` instead of `django-admin`, it configures project specific things like the PYTHONPATH. – Klaus D. Nov 24 '19 at 06:14
  • I understand that and that's why I added comments regarding the use of Django cache framework because accessing the cache gives the same error: ```Requested setting CACHES, but settings are not configured```. I'm using django-admin to simplify and reproduce the error without having django cache to be involved – Daniel Yang Nov 24 '19 at 06:20

1 Answers1

0

In your list I did not see the virtual env activation.

Did you activate the virtual env ?

''' source activate testproject '''

Noam Segev
  • 51
  • 6