TypeError: context must be a dict rather than RequestContext.

TypeError: context must be a dict rather than RequestContext.
def index(request):
报这个错的时候:

# 1.加载模板文件
temp = loader.get_template('booktest/index.html')

# 2. 定义模板上下文,给模板文件传递数据
# context= RequestContext(request,{})   #这样会报上面的错  错误
context = {}  #改成这样就可以了  正确

# 3. 模板渲染,产生标准的html内容
res_html = temp.render(context)

# 4.返回给浏览器
return HttpResponse(res_html)
发布了35 篇原创文章 · 获赞 0 · 访问量 435

猜你喜欢

转载自blog.csdn.net/mengzh620/article/details/103000239