我试过使用 https://docs.djangoproject.com/en/dev/topics/http/views/教程,但我仍然得到标准的 404 html 页面。我想切换到我的自定义 View
handler404 = 'myview.views.custom_page_not_found' ,
我确实调试了它(使用 eclipse),然后 handler404(old value -'django.config.default.views.page_not_found
) 的值被更改为我给定的新值 (' myview.views.custom_page_not_found')。但它仍然显示旧的 404 页面。我已经将 settings.py DEBUG 更改为 False 然后它显示自定义页面。但它有一些缺点(它不会加载静态文件和所有,DEBUG = false
不是正确的方法)所以我不得不重置为 True。
我是否必须进行一些其他修改才能实现它?
最佳答案
我认为您不能毫无困难地更改 DEBUG = True
模式下的 404 页面。
文档中有提示(https://docs.djangoproject.com/en/dev/topics/http/views/#the-404-page-not-found-view):
If DEBUG is set to True (in your settings module), then your 404 view will never be used, and your URLconf will be displayed instead, with some debug information.
关于python - 如何覆盖 Django 中的标准 handler404、handler403、handler500?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19160164/