Django handler500作为基于类的视图 [英] Django handler500 as a Class Based View
本文介绍了Django handler500作为基于类的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么这不工作
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.
我发现这个说明你描述的是你自己在脚下拍摄自己的类视图,为什么会这样?
I found this set of notes that describe that you are shooting yourself in the foot to use class based views there, why is that?
编辑:我已经结束了使用这个。 ..但我仍然希望有人会告诉我如何获得原始的衬衫或类似的工作
I have ended up using this ... but I am still hoping someone out there would tell me how to get the original oneliner or similar working
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()
推荐答案
我宁愿在vanilla Django中使用带有静态HTML的股票500模板,然后用代码执行任何操作。这是一个我相信不应该触及的切换。
I would rather just use stock 500 templates with static HTML in vanilla Django then do anything with code. This is one toggle I believe should not be touched.
这篇关于Django handler500作为基于类的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文