我尝试过使用https://docs.djangoproject.com/en/dev/topics/http/views/教程,但我仍然得到了标准的404html页面。我想切换到我的自定义视图
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调试更改为False,然后它将显示自定义页面。但是它有一些缺点(它不会加载静态文件,而且,DEBUG = false不是正确的方法),所以我不得不重置为True。
为了实现这一点,我还需要做一些其他的修改吗?
发布于 2013-10-03 14:51:17
我认为您不可能毫无困难地在DEBUG = True模式下更改404页。
文档(https://docs.djangoproject.com/en/dev/topics/http/views/#the-404-page-not-found-view)中有一个提示:
如果调试设置为True (在您的设置模块中),那么您的404视图将永远不会被使用,您的URLconf将被显示,并包含一些调试信息。
发布于 2014-11-12 19:47:30
尝试将其添加到主urls.py的底部:
if settings.DEBUG:
urlpatterns += patterns('',
(r'^404/$', TemplateResponse, {'template': '404.html'}))将404.html交换到您使用的适当模板,我相信404.html是默认的。然后,使用debug=True,您可以测试您的404页。
如果您想用Debug=True测试它,那么您需要在主urls.py的底部测试它:
#Enable static for runserver with debug false
from django.conf import settings
if settings.DEBUG is False: #if DEBUG is True it will be served automatically
urlpatterns += patterns('',
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
)在使用DEBUG = False运行时,不要忘记收集静态:
python manage.py collectstatic希望这有帮助,干杯!
https://stackoverflow.com/questions/19160164
复制相似问题