Django oscar <wsgirequest get =“”>中的密钥[basket]查找失败

时间:2017-02-02 21:13:20

标签: python django python-3.5 django-oscar

我是django-oscar的新手,这是我第一次尝试使用它启动网站。尝试加载网页时,我面临以下堆栈跟踪(localhost:8000)。我试图在互联网上搜索很多,但我找不到任何解决方案。

Image     环境:     请求方法:GET     请求网址:http://localhost:8000/

Django Version: 1.9
Python Version: 3.5.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'django.contrib.flatpages',
 'compressor',
 'widget_tweaks',
 'oscar',
 'oscar.apps.analytics',
 'oscar.apps.checkout',
 'oscar.apps.address',
 'oscar.apps.shipping',
 'oscar.apps.catalogue',
 'oscar.apps.catalogue.reviews',
 'oscar.apps.partner',
 'oscar.apps.basket',
 'oscar.apps.payment',
 'oscar.apps.offer',
 'oscar.apps.order',
 'oscar.apps.customer',
 'oscar.apps.promotions',
 'oscar.apps.search',
 'oscar.apps.voucher',
 'oscar.apps.wishlists',
 'oscar.apps.dashboard',
 'oscar.apps.dashboard.reports',
 'oscar.apps.dashboard.users',
 'oscar.apps.dashboard.orders',
 'oscar.apps.dashboard.promotions',
 'oscar.apps.dashboard.catalogue',
 'oscar.apps.dashboard.offers',
 'oscar.apps.dashboard.partners',
 'oscar.apps.dashboard.pages',
 'oscar.apps.dashboard.ranges',
 'oscar.apps.dashboard.reviews',
 'oscar.apps.dashboard.vouchers',
 'oscar.apps.dashboard.communications',
 'oscar.apps.dashboard.shipping',
 'haystack',
 'treebeard',
 'sorl.thumbnail',
 'django_tables2']

Installed Middleware:<br>
['django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware']


Template error:
In template
/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/oscar/templates/oscar/promotions/home.html, error at line 0
   Failed lookup for key [%s] in %r   1 : {% extends "layout_2_col.html" %}
   2 : {% load i18n %}
   3 : 
   4 : {% block navigation %}
   5 :     {% include "partials/nav_primary.html" with expand_dropdown=1 %}
   6 : {% endblock %}
   7 : 
   8 : {% block header %}{% endblock %}
   9 : 
   10 : {% block column_left %}


Traceback:

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in _resolve_lookup
  879.                     current = current[bit]

During handling of the above exception ('WSGIRequest' object is not subscriptable), another exception occurred:

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in _resolve_lookup
  887.                         current = getattr(current, bit)

During handling of the above exception ('WSGIRequest' object has no attribute 'basket'), another exception occurred:

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in _resolve_lookup
  894.                             current = current[int(bit)]

During handling of the above exception (invalid literal for int() with base 10: 'basket'), another exception occurred:

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
  174.                     response = self.process_exception_by_middleware(e, request)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
  172.                     response = response.render()

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/response.py" in render
  160.             self.content = self.rendered_content

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/response.py" in rendered_content
  137.         content = template.render(context, self._request)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/backends/django.py" in render
  95.             return self.template.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render
  206.                     return self._render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in _render
  197.         return self.nodelist.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render
  988.                 bit = node.render_annotated(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  955.             return self.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  173.         return compiled_parent._render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in _render
  197.         return self.nodelist.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render
  988.                 bit = node.render_annotated(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  955.             return self.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  173.         return compiled_parent._render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in _render
  197.         return self.nodelist.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render
  988.                 bit = node.render_annotated(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  955.             return self.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  173.         return compiled_parent._render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in _render
  197.         return self.nodelist.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render
  988.                 bit = node.render_annotated(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  955.             return self.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  69.                 result = block.nodelist.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render
  988.                 bit = node.render_annotated(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  955.             return self.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  69.                 result = block.nodelist.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render
  988.                 bit = node.render_annotated(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  955.             return self.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  209.                 return template.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render
  208.                 return self._render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in _render
  197.         return self.nodelist.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render
  988.                 bit = node.render_annotated(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  955.             return self.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/defaulttags.py" in render
  326.                 return nodelist.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render
  988.                 bit = node.render_annotated(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  955.             return self.render(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in render
  1039.             output = self.filter_expression.resolve(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in resolve
  726.                     arg_vals.append(arg.resolve(context))

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in resolve
  846.             value = self._resolve_lookup(context)

File "/Users/rohit.rawat/.virtualenvs/env/lib/python3.5/site-packages/django/template/base.py" in _resolve_lookup
  901.                                                        (bit, current))  # missing attribute

Exception Type: VariableDoesNotExist at /
Exception Value: Failed lookup for key [basket] in "<WSGIRequest: GET '/'>"


此外,如果您可以为django建议更好或更不容易出错的电子商务框架,那就太棒了!

2 个答案:

答案 0 :(得分:2)

我遇到了这个问题,因为我在settings.py中使用了MIDDLEWARE而不是MIDDLEWARE_CLASSES。我一改变了,一切都运转了。

答案 1 :(得分:-1)

oscar.apps.basket.middleware.BasketMiddleware设置中缺少middleware