如何使用基于类的视图指定Django的自定义404视图? [英] How to specify a custom 404 view for Django using Class Based Views?
本文介绍了如何使用基于类的视图指定Django的自定义404视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Django,您可以通过在根目录 urls.py
中覆盖默认的404页面:
Using Django, you can override the default 404 page by doing this in the root urls.py
:
handler404 = 'path.to.views.custom404'
使用基于类的视图时如何执行此操作?我不能弄清楚,文档似乎没有说什么。
How to do this when using Class based views? I can't figure it out and the documentation doesn't seem to say anything.
我试过:
handler404 = 'path.to.view.Custom404.as_view'
推荐答案
没关系,我忘了尝试一下:
Never mind, I forgot to try this:
from path.to.view import Custom404
handler404 = Custom404.as_view()
现在看起来很简单,它可能不值得StackOverflow的问题。
Seems so simple now, it probably doesn't merit a question on StackOverflow.
这篇关于如何使用基于类的视图指定Django的自定义404视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文