Django.core.exceptions。配置不当:

2024-04-19 07:39:11 发布

您现在位置:Python中文网/ 问答频道 /正文

在基于http://michal.karzynski.pl/blog/2013/07/14/using-redis-as-django-session-store-and-cache-backend/的ubuntuec2节点上安装了redis和django之后,我一直在尝试在命令行使用低级缓存api(https://docs.djangoproject.com/en/1.7/topics/cache/#the-low-level-cache-api

 Python 3.4.0 (default, Apr 11 2014, 13:05:11)
 [GCC 4.8.2] on linux
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import django
 >>> import redis
 >>> from django.core.cache import cache
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/django/core/cache/__init__.py", line 34, in <module>
     if DEFAULT_CACHE_ALIAS not in settings.CACHES:
   File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/django/conf/__init__.py", line 46, in __getattr__
     self._setup(name)
   File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/django/conf/__init__.py", line 40, 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.

我有一个django项目,并将中间件设置为:

^{pr2}$

我怎样才能让它工作?在


Tags: djangoincoreimportrediscachehomesettings