Django通过消息提高404 [英] Django raising 404 with a message
本文介绍了Django通过消息提高404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在脚本的不同位置引发404错误消息,例如: Http404( some error msg:%s%msg)
因此,在我的urls.py中,我包括了:
I like to raise 404 with some error message at different places in the script eg: Http404("some error msg: %s" %msg)
So, in my urls.py I included:
handler404 = Custom404.as_view()
任何人都可以告诉我如何处理我的观点中的错误。我是Django的新手,所以举个例子对您有很大帮助。
提前谢谢。
Can anyone please tell me how should I be handling the error in my views. I'm fairly new to Django, so an example would help a lot.
Many thanks in advance.
推荐答案
通常,404错误是找不到页面错误-它不应具有可自定义的消息,仅仅是因为仅当未找到页面时才应引发该消息。
In general, 404 error is "page not found" error - it should not have customizable messages, simply because it should be raised only when a page is not found.
您可以返回 TemplateResponse
的状态参数设置为 404
这篇关于Django通过消息提高404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文