Import Module CSRF issue: Django
Question: Short Notes - I'm trying to call `from django.middleware import csrf` at
python shell. its throwing/showing a message.

See shell code:

    
    
    C:\>python
    Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win
    32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import django
    >>> from django import middleware
    >>> from django.middleware import csrf
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Python27\lib\site-packages\django\middleware\csrf.py", line 16, in <m
    odule>
        from django.utils.cache import patch_vary_headers
      File "C:\Python27\lib\site-packages\django\utils\cache.py", line 26, in <modul
    e>
        from django.core.cache import get_cache
      File "C:\Python27\lib\site-packages\django\core\cache\__init__.py", line 70, i
    n <module>
        if DEFAULT_CACHE_ALIAS not in settings.CACHES:
      File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 53, in __ge
    tattr__
        self._setup(name)
      File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 46, in _set
    up
        % (desc, ENVIRONMENT_VARIABLE))
    django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but setti
    ngs are not configured. You must either define the environment variable DJANGO_S
    ETTINGS_MODULE or call settings.configure() before accessing settings.
    >>>
    

Can anybody gone through this & how to sort out this?


Answer: You can't access and run django projects from python shell. Django doesn't
know what project you want to work on.

You have to do one of these things:

    
    
    1. python manage.py shell
    2. Set DJANGO_SETTINGS_MODULE environment variable in your OS to mysite.settings
    3. Use setup_environ in the python interpreter:
       from django.core.management import setup_environ
       from mysite import settings
       setup_environ(settings)
    

