开发者

Displaying Http404 parameter in 404.html template

开发者 https://www.devze.com 2023-03-31 04:50 出处:网络
If I raise a 404 exception in Django using raise Http404(\"Error text\") how can I display the Http404 parameter (\"Error text\" in this case) in my 404.html template?

If I raise a 404 exception in Django using

raise Http404("Error text")

how can I display the Http404 parameter ("Error text" in this case) in my 404.html template?

(I am using the default Django 开发者_StackOverflow社区view to handle 404 errors.)


Check out defining your own 404 Handler. In the view that you write, you can receive the error text and then pass it to the 404 templates.

Keep in mind that based on the HTTP standards, the 404 error is supposed to be for Page Not Found, not a generic error page. Depending on your use case, maybe reevaluate the use of form validation, or other error messages that can inform the user of the problem before the 404 redirect.

0

精彩评论

暂无评论...
验证码 换一张
取 消