在学习Django 自动以过滤器时调试突然报错context must be a dict rather than Context.截图如下。
此时views.py的代码如下,使用了get_template函数读取模板,但是后边render中又使用了Context,这是有问题的。在Template类中使用Context是可以的,但是get_template中使用会报错呢。
经调查后修改代码如下后即去掉了Context后,在运行程序,正常了。
def hello_filter(request):
t=loader.get_template('hello_filter.html')
html=t.render({'Web':'Web django Django'})
return HttpResponse(html)