为什么这不起作用
handler500 = TemplateView.as_view(template_name="500.html")
我得到以下异常:
Traceback (most recent call last):
File "/usr/lib/python2.6/wsgiref/handlers.py", line 94, in run
self.finish_response()
File "/usr/lib/python2.6/wsgiref/handlers.py", line 134, in finish_response
for data in self.result:
File "/home/hatem/projects/leadsift_app/.virtualenv/lib/python2.6/site-packages/django/template/response.py", line 117, in __iter__
raise ContentNotRenderedError('The response content must be 'ContentNotRenderedError: The response content must be rendered before it can be iterated over.
我发现这组笔记描述了你正在用脚射击自己以在那里使用基于类的视图,这是为什么呢?
编辑:我最终使用了这个......但我仍然希望有人会告诉我如何让原来的 oneliner 或类似的工作
class Handler500(TemplateView):
template_name = "500.html"
@classmethod
def as_error_view(cls):
v = cls.as_view()
def view(request):
r = v(request)
r.render()
return r
return view
handler500 = Handler500.as_error_view()