我收到一条消息TypeError上下文必须是dict而不是Context。但不知道如何解决它。
def comment(request,id):
if id:
r = Restaurant.objects.get(id=id)
else:
return HttpResponseRedirect("/restaurants_list/")
if request.POST:
visitor = request.POST['visitor']
content = request.POST['content']
email = request.POST['email']
date_time = timezone.localtime(timezone())
Comment.objects.create(
visitor=visitor,
email=email,
content=content,
date_time=date_time,
restaurant=r
)
return render_to_response('comments.html', RequestContext(request, locals()))
答案 0 :(得分:1)
您可以看到context
参数的说明:
要添加到模板上下文的值的字典。默认情况下,这是一个空字典。如果字典中的值是可调用的,则视图将在呈现模板之前调用它。
更改行:
return render_to_response('comments.html', RequestContext(request, locals()))
致:
return render_to_response('comments.html', context=locals())