如何在Django开发环境中测试500.html错误页面? [英] How to test 500.html error page in django development env?
问题描述
我正在将Django用于一个项目,并且已经在生产中。
I am using Django for a project and is already in production.
在生产环境中,只要发生服务器错误,就会呈现500.html。
In the production environment 500.html is rendered whenever a server error occurs.
如何在开发环境中测试500.html的渲染?或如何在开发环境中渲染500.html,如果我关闭调试,我仍然会收到错误,而不是500.html
How do I test the rendering of 500.html in dev environment? Or how do I render 500.html in dev, if I turn-off debug I still get the errors and not 500.html
背景:我包括一些基于在页面上,当调用500.html并想在开发环境中对其进行调试时,某些页面会丢失。
background: I include some page elements based on a page and some are missing when 500.html is called and want to debug it in dev environment.
推荐答案
我不想关闭DEBUG。相反,我将以下代码片段放在urls.py中:
I prefer not to turn DEBUG off. Instead I put the following snippet in the urls.py:
if settings.DEBUG:
urlpatterns += patterns('',
(r'^500/$', 'your_custom_view_if_you_wrote_one'),
(r'^404/$', 'django.views.generic.simple.direct_to_template', {'template': '404.html'}),
)
在上面的代码段中,错误页面使用自定义视图,不过您可以轻松地将其替换为Django的direct_to_template视图。
In the snippet above, the error page uses a custom view, you can easily replace it with Django's direct_to_template view though.
现在您可以通过调用其网址来测试500和404页面: http://example.com/500 和 http://example.com/404
Now you can test 500 and 404 pages by calling their urls: http://example.com/500 and http://example.com/404
这篇关于如何在Django开发环境中测试500.html错误页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!