Reputation: 1
Our Django application uses Django Rest Framework, Oauth2 and double settings - one to develop and other to production, and a general one called base.py. The development.py is currently set up on manage.py file. We are also using django-cors-headers package.
This exception starts yesterday when I use ./manage.py runserver
or another command. I tried to fix it. I read many posts from here (Stackoverflow) and in other websites, but I did not make it.
Could someone help me, please?
Traceback (most recent call last):
File "./manage.py", line 5, in <module>
from settings import base, development
File "/home/ijdev/Área de Trabalho/izio/izio-bank/settings/base.py", line 12, in <module>
from corsheaders.defaults import default_methods as cors_default_methods
File "/home/ijdev/Área de Trabalho/izio/Izioenv/lib/python3.7/site-packages/corsheaders/defaults.py", line 14, in <module>
CORS_ALLOW_HEADERS = getattr(settings, 'CORS_ALLOW_HEADERS', default_headers)
File "/home/ijdev/Área de Trabalho/izio/Izioenv/lib/python3.7/site-packages/django/conf/__init__.py", line 79, in __getattr__
self._setup(name)
File "/home/ijdev/Área de Trabalho/izio/Izioenv/lib/python3.7/site-packages/django/conf/__init__.py", line 64, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CORS_ALLOW_HEADERS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Upvotes: 0
Views: 217
Reputation: 309009
In your base settings you have
from corsheaders.defaults import default_methods as cors_default_methods
This causes a circular import because corsheaders tries to import settings.
To solve the problem, remove the import from settings.
Upvotes: 1