def index(request):
temp = loader.get_template('booktest/index.html')
context =RequestContext(request,{})
res_html =temp.render(context)
return HttpResponse(res_html)
报错:
context must be a dict rather than RequestContext.
解释:模板渲染中传入的内容只能是字典,不能是Context对象类型。
原因:问题主要出在版本上,1.1版本中可以直接传入Context对象,在1.11后只能传入字典。
修改代码:
def index(request):
temp = loader.get_template('booktest/index.html')
# context =RequestContext(request,{})
res_html =temp.render(context=locals(),request=request)
return HttpResponse(res_html)