gpt4 book ai didi

python - Django.core.exceptions.ImproperlyConfigured :

转载 作者:IT王子 更新时间:2023-10-29 06:08:36 25 4
gpt4 key购买 nike

在ubuntu ec2节点上安装redis和django后,基于http://michal.karzynski.pl/blog/2013/07/14/using-redis-as-django-session-store-and-cache-backend/ , 我一直在尝试在命令行中使用低级缓存 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 项目,中间件设置如下:

MIDDLEWARE_CLASSES = (
'django.middleware.cache.UpdateCacheMiddleware', # This must be first on the list
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware', # This must be last
)

我怎样才能让它工作?

最佳答案

要试验 django,您应该使用以下命令运行 shell:

python manage.py shell

这将加载项目的设置。

关于python - Django.core.exceptions.ImproperlyConfigured :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29190526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com