13

所以我有一个不使用数据库的 Django 项目('DATABASES' 设置被注释掉了)。我选择使用 Django,因为将来我可能需要数据库功能。无论如何,我已经在这个项目上工作了几个月,没有任何问题。我正在运行 Linux Mint,并且在使用python manage.py runserver到目前为止使用该命令没有遇到任何问题。

好吧,今天我启动了应用程序并毫无问题地启动了本地服务器。然后我尝试在浏览器中打开该应用程序并收到相当可怕的错误消息:

Traceback (most recent call last):
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/sessions/backends/base.py", line 170, in _get_session
    return self._session_cache
AttributeError: 'SessionStore' object has no attribute '_session_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/core/handlers/base.py", line 87, in get_response
    response = middleware_method(request)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/auth/middleware.py", line 34, in process_request
    if user and hasattr(user, 'get_session_auth_hash'):
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/utils/functional.py", line 224, in inner
    self._setup()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/utils/functional.py", line 357, in _setup
    self._wrapped = self._setupfunc()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/auth/middleware.py", line 23, in <lambda>
    request.user = SimpleLazyObject(lambda: get_user(request))
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/auth/middleware.py", line 11, in get_user
    request._cached_user = auth.get_user(request)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/auth/__init__.py", line 151, in get_user
    user_id = request.session[SESSION_KEY]
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/sessions/backends/base.py", line 49, in __getitem__
    return self._session[key]
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/sessions/backends/base.py", line 175, in _get_session
    self._session_cache = self.load()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/sessions/backends/db.py", line 21, in load
    expire_date__gt=timezone.now()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/query.py", line 351, in get
    num = len(clone)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/query.py", line 122, in __len__
    self._fetch_all()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/query.py", line 966, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/query.py", line 265, in iterator
    for row in compiler.results_iter():
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/sql/compiler.py", line 700, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/sql/compiler.py", line 775, in execute_sql
    sql, params = self.as_sql()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/sql/compiler.py", line 100, in as_sql
    out_cols, s_params = self.get_columns(with_col_aliases)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/sql/compiler.py", line 246, in get_columns
    col_aliases)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/sql/compiler.py", line 328, in get_default_columns
    r = '%s.%s' % (qn(alias), qn2(column))
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/sql/compiler.py", line 62, in __call__
    r = self.connection.ops.quote_name(name)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/backends/dummy/base.py", line 18, in complain
    raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/sessions/backends/base.py", line 170, in _get_session
    return self._session_cache
AttributeError: 'SessionStore' object has no attribute '_session_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.3/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/staticfiles/handlers.py", line 64, in __call__
    return self.application(environ, start_response)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    response = self.get_response(request)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/core/handlers/base.py", line 199, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/core/handlers/base.py", line 236, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/views/debug.py", line 91, in technical_500_response
    html = reporter.get_traceback_html()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/views/debug.py", line 349, in get_traceback_html
    c = Context(self.get_traceback_data(), use_l10n=False)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/views/debug.py", line 307, in get_traceback_data
    frames = self.get_traceback_frames()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/views/debug.py", line 465, in get_traceback_frames
    'vars': self.filter.get_traceback_frame_variables(self.request, tb.tb_frame),
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/views/debug.py", line 232, in get_traceback_frame_variables
    cleansed[name] = self.cleanse_special_types(request, value)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/views/debug.py", line 187, in cleanse_special_types
    if isinstance(value, HttpRequest):
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/utils/functional.py", line 224, in inner
    self._setup()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/utils/functional.py", line 357, in _setup
    self._wrapped = self._setupfunc()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/auth/middleware.py", line 23, in <lambda>
    request.user = SimpleLazyObject(lambda: get_user(request))
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/auth/middleware.py", line 11, in get_user
    request._cached_user = auth.get_user(request)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/auth/__init__.py", line 151, in get_user
    user_id = request.session[SESSION_KEY]
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/sessions/backends/base.py", line 49, in __getitem__
    return self._session[key]
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/sessions/backends/base.py", line 175, in _get_session
    self._session_cache = self.load()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/contrib/sessions/backends/db.py", line 21, in load
    expire_date__gt=timezone.now()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/query.py", line 351, in get
    num = len(clone)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/query.py", line 122, in __len__
    self._fetch_all()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/query.py", line 966, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/query.py", line 265, in iterator
    for row in compiler.results_iter():
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/sql/compiler.py", line 700, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/sql/compiler.py", line 775, in execute_sql
    sql, params = self.as_sql()
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/sql/compiler.py", line 100, in as_sql
    out_cols, s_params = self.get_columns(with_col_aliases)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/sql/compiler.py", line 246, in get_columns
    col_aliases)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/sql/compiler.py", line 328, in get_default_columns
    r = '%s.%s' % (qn(alias), qn2(column))
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/models/sql/compiler.py", line 62, in __call__
    r = self.connection.ops.quote_name(name)
  File "/home/peter/.virtualenvs/vis_it/lib/python3.3/site-packages/django/db/backends/dummy/base.py", line 18, in complain
    raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
[28/Nov/2014 13:18:54] "GET / HTTP/1.1" 500 59

自从我上次使用该应用程序以来,我还没有碰过它,那时它运行良好。我真的不知道这是在说什么,因为我没有实现缓存,也没有使用数据库……我问过一些熟悉 Django 的大学,也不知道这是什么。有任何想法吗?我还尝试根据在线帖子的建议将 DATABASES 设置为空 dict {},但没有效果。有点吃亏。

编辑:我想我应该提一下,自从我上次接触这个项目以来,我已经开始并建立了一个使用数据库的新 Django 项目。这个项目是否有可能以某种方式被缓存并破坏了我目前正在尝试的项目?

EDIT2:我应该指出,这个 webapp 目前在http://mrcagney-maps.com上运行和工作。代码完全一样(自从我上次推送到服务器后就没有碰过它)。真的很奇怪。

4

7 回答 7

32

对于未来的 Google 员工 - 我遇到了这个问题,上述解决方案对我不起作用。我有用的是在 Chrome 中为 127.0.0.1 URL 清除/删除我的 cookie。因此,转到设置或按CMD+,Cookies 和其他站点数据,然后找到 127.0.0.1 或 localhost 并删除这些 cookie。刷新本地开发主机页面,错误应该消失了。这与损坏的会话/cookie 文件有关。

于 2020-08-25T02:42:02.963 回答
6

该错误AttributeError: 'SessionStore' object has no attribute '_session_cache'可能源于没有 django_session 表的数据库。但是,由于您没有使用表,因此您需要确保项目设置文件'django.contrib.sessions.middleware.SessionMiddleware'中的MIDDLEWARE_CLASSES中没有 。如果它在那里,它将查找存储会话的数据库表,从而导致上述错误。

于 2014-11-28T04:17:00.383 回答
6

我不确定为什么我开始收到此错误,但它涉及升级。我刚刚删除了所有会话,重新登录后一切正常。

# from the shell but equivalent sql would work fine too
from django.contrib.sessions.models import Session
Session.objects.all().delete()
于 2020-12-07T17:57:17.417 回答
3

这对我有用。由于您的应用程序中没有数据库。默认情况下,管理页面会查找数据库。所以首先让我们创建默认数据库。

关闭服务器并运行

python manage.py makemigrations
python manage.py migrate

现在为您的应用程序创建管理员或超级用户。填写用户名和密码。

python manage.py createsuperuser

现在重新启动您的服务器并进入管理页面

python manage.py runserver
于 2019-05-21T04:24:15.917 回答
0

通过 Postman 遇到此问题的用户请确保请求标头中的Cache-Control值为no-cache.

如果不是,则清除域的 cookie 数据。

邮递员截图

于 2021-04-13T15:48:41.357 回答
0

在正常情况下,当我们使用

from django.http import JsonResponse

对于发送响应,我们不需要使用会话。

但是当我们使用某些包时,例如djangorestframework我们强制使用会话。

会话需要存储在 sqllite、mysql 或其他中,然后我们需要运行以下命令:

python manage.py makemigrations
python manage.py migrate
于 2021-08-27T09:30:59.563 回答
0

升级我的 wagtail 版本后对我抛出了同样的错误......所以,对我来说工作更简单的解决方案或者你没有注意到:D 实际上我打开了浏览器 > F12 > 存储选项卡并删除所有 Cookie 和所有其他缓存数据

于 2020-12-24T23:42:53.453 回答