Django project looking for “attribute '_session_cache'”

六眼飞鱼酱① 提交于 2019-11-28 07:44:58

问题


So I have a Django project that doesn't use a database (the 'DATABASES' setting is commented out). I chose to use Django as there's a chance I will need the database functionality in the future. Anyway, I've been working on and off of tbhis project for a couple of months with no problems. I'm running Linux Mint and have had no troubles using the python manage.py runserver command so far.

Well, today I fired up the app and started the local server with no problems. I then tried to open the app in my browser and received the rather hideous error message:

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

I've not touched the app since I last worked on it and it was working fine then. I really have no idea what this is talking about as I have no caches implemented and am not using a database... I've asked a few colleges who are familiar with Django and have no idea what this is either. Any Ideas? I've also tried setting DATABASES to an empty dict {} on the advice of a post online but to no effect. At a bit of a loss.

EDIT: Thought I should mention that in the interim since I last touched this project, I've since started and set up a new Django project that does use a database. Is it possible that this project is somehow cached and breaking the one I'm currently trying to work on?

EDIT2: I should point out that this webapp is currently live and working at http://mrcagney-maps.com. The code is exactly the same (having not touched it since I last pushed to the server). Really weird.


回答1:


The error AttributeError: 'SessionStore' object has no attribute '_session_cache' can stem from the database not having a django_session table. However, since you are not using a table, you would need to make sure that you don't have the 'django.contrib.sessions.middleware.SessionMiddleware' in your MIDDLEWARE_CLASSES in the project's settings file. If it is in there, it will look for a database table which stores the sessions, causing the above error.




回答2:


Here is what worked for me. Since there is no databases in your application. Admin page looks for the database be it default. So first lets create the default databases.

Shut down your servers and run

python manage.py makemigrations
python manage.py migrate

Now create the admin or superuser for your application. Fill username and password.

python manage.py createsuperuser

Now restart your server and go the admin page

python manage.py runserver


来源:https://stackoverflow.com/questions/27180353/django-project-looking-for-attribute-session-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!