自定义 Django 404 页面和 Django 调试页面
我正在部署 Django 网页,我喜欢 Django 调试 404 页面以及出现 python 错误时的 Django 页面。然而,这些并不适合在线网页。所以我制作了一个自定义的404页面。然而,对于我和我的 IP 地址来说,我仍然希望 Django 调试页面出现。如果我将“调试”设置为“假”,是否可以执行此操作?
I am deploying a Django webpage and I love the Django Debug 404 page and and the Django page when there is a python error. However these aren't appropriate for a webpage that is going online. So I have made a custom 404 page. However, for me, and my IP address, I want to still have the Django Debug pages come up. Is there anyway to do this if I set Debug to false?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过在 urlconf 中设置 handler404 来定义自己的 404 处理程序视图。默认的 handler404 是 django.views.defaults.page_not_found ,它基本上只渲染 404.html 模板。
如果你把它放在你的 urlconf 中,它将显示某个 IP 的“技术”404 响应(漂亮的黄页),并使用 Django 的默认 404 生产视图来显示其他 IP:
我建议你设置适当的日志记录你404错误。对于您可以指定的规则,Django 可以通过电子邮件或记录 404 错误以及生产环境中发生的异常情况。
请参阅有关错误报告和logging (日志框架是在1.3中添加的)
You can define your own handler-view for 404s, by setting handler404 in your urlconf. The default handler404 is
django.views.defaults.page_not_found
, which basically just renders the404.html
template.If you put this in your urlconf, it will show the "technical" 404 response (the nice yellow page) for a certain IP, and use Django's default 404-production view for other IPs:
I would advise you to set up proper logging for you 404 errors. Django can e-mail or log 404s and exceptions for you that happens in your production environment for rules that you can specify.
See the documentation on error reporting and logging (The logging framework was added in 1.3)