导入模块CSRF问题:Django

时间:2013-08-06 10:51:43

标签: python django google-app-engine

简短注释 - 我试图在python shell上调用from django.middleware import csrf。 它投掷/显示信息。

参见shell代码:

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.
>>>

任何人都可以通过这个&amp;如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您无法从python shell访问和运行django项目。 Django不知道你想要做什么项目。

你必须做以下事情之一:

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)