Django on Pycharm: Misconfigured with DJANGO_SETTINGS_MODULE
I am trying to use Pycharm Community Edition to improve my code in my Django application, but I cannot run all my Django code that I would like. I keep getting this track ...
Traceback (most recent call last):
File "C:/Users/Jaysp_000/firstSite/PROJECTone/blog_static/views.py", line 1, in <module>
from django.views.decorators.csrf import csrf_exempt
File "C:\Python34\lib\site-packages\django\views\decorators\csrf.py", line 3, in <module>
from django.middleware.csrf import CsrfViewMiddleware, get_token
File "C:\Python34\lib\site-packages\django\middleware\csrf.py", line 14, in <module>
from django.utils.cache import patch_vary_headers
File "C:\Python34\lib\site-packages\django\utils\cache.py", line 26, in <module>
from django.core.cache import caches
File "C:\Python34\lib\site-packages\django\core\cache\__init__.py", line 34, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 48, in __getattr__
self._setup(name)
File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
This error seems to be related to django.views.decortors.csrf.csrf_exempt
which I imported into the views.py file. I tried other files and they didn't give me any problems. There is something special about this, but I don't know what.
from django.views.decortors.csrf import csrf_exempt
@csrf_exempt
def handle_hook(request):
from django.http import HttpResponse
from django.core.management import call_command
result = call_command('update_blog', verbosity = 0)
return HttpResponse(result)
The same problem occurs when I try to run the code in python shell (I use 3.4) and when i import django.http.request as request
. I type handle_hook(request)
and I get the same error.
I was told that I should either define the DJANGO_SETTINGS_MODULE environment variable or call the settings.configure () before accessing the settings, but I don't know how. I've looked around and I'm not sure what these methods specifically tell about my problem. Any hints?
source to share