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屋!
查看全文