使用渲染时的值错误(django 1.7.1)
Value Error when render used (django 1.7.1)
我有一个错误
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/user/accounter/apps/accounter/views.py" in unit_view
24. return render(request, 'accounter/unit.html', context)
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts.py" in render
48. return HttpResponse(loader.render_to_string(*args, **kwargs),
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in render_to_string
177. with context_instance.push(dictionary):
File "/usr/local/lib/python2.7/dist-packages/django/template/context.py" in push
54. return ContextDict(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/template/context.py" in __init__
19. super(ContextDict, self).__init__(*args, **kwargs)
Exception Type: ValueError at /accounter/1/
Exception Value: dictionary update sequence element #0 has length 3; 2 is required
还有我的查看源码:
class ProductListView(generic.ListView):
model = Product
def get_queryset(self):
return Product.objects.all()
def unit_view(request, product_id):
context = Context({
'product': Product.objects.get(pk=product_id).name,
'ship_units': ShipUnit.objects.filter(product = product_id),
'shop_units': ShopUnit.objects.filter(product = product_id),
})
return render(request, 'accounter/unit.html', context)
我不知道是什么问题。我已经阅读了有关使用渲染和上下文的文档,以及所有示例。但是找不到我的错误在哪里。
render
是快捷键;它不需要 Context 对象,它需要一个普通的字典。
context = {
'product': Product.objects.get(pk=product_id).name,
'ship_units': ShipUnit.objects.filter(product = product_id),
'shop_units': ShopUnit.objects.filter(product = product_id),
}
我有一个错误
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/user/accounter/apps/accounter/views.py" in unit_view
24. return render(request, 'accounter/unit.html', context)
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts.py" in render
48. return HttpResponse(loader.render_to_string(*args, **kwargs),
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in render_to_string
177. with context_instance.push(dictionary):
File "/usr/local/lib/python2.7/dist-packages/django/template/context.py" in push
54. return ContextDict(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/template/context.py" in __init__
19. super(ContextDict, self).__init__(*args, **kwargs)
Exception Type: ValueError at /accounter/1/
Exception Value: dictionary update sequence element #0 has length 3; 2 is required
还有我的查看源码:
class ProductListView(generic.ListView):
model = Product
def get_queryset(self):
return Product.objects.all()
def unit_view(request, product_id):
context = Context({
'product': Product.objects.get(pk=product_id).name,
'ship_units': ShipUnit.objects.filter(product = product_id),
'shop_units': ShopUnit.objects.filter(product = product_id),
})
return render(request, 'accounter/unit.html', context)
我不知道是什么问题。我已经阅读了有关使用渲染和上下文的文档,以及所有示例。但是找不到我的错误在哪里。
render
是快捷键;它不需要 Context 对象,它需要一个普通的字典。
context = {
'product': Product.objects.get(pk=product_id).name,
'ship_units': ShipUnit.objects.filter(product = product_id),
'shop_units': ShopUnit.objects.filter(product = product_id),
}