- 使用Django1.11,在views.py中如果这样写
def index(request): # return HttpResponse("欢迎来到 Django首页!") booklist = BookInfo.objects.all() template = loader.get_template('booktest/index.html') context = RequestContext(request, {'booklist': booklist}) return HttpResponse(template.render(context))
- 会报错如下
Exception Type: TypeError Exception Value: context must be a dict rather than RequestContext.
- 解决办法
def index(request): # return HttpResponse("欢迎来到 Django首页!") booklist = BookInfo.objects.all() template = loader.get_template('booktest/index.html') # context = RequestContext(request, {'booklist': booklist}) context = {'booklist': booklist} return HttpResponse(template.render(context)
文章出处:https://blog.csdn.net/fly910905/article/details/77940882