如何在(django)开发环境中测试500.html? [英] How to test 500.html in (django) development env?

查看:290
本文介绍了如何在(django)开发环境中测试500.html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在生产环境中,当出现服务器错误时,将会呈现500.html。



如何在开发环境中测试500.html的渲染?或者如何在开发中渲染500.html,如果我关闭调试我仍然收到错误,而不是500.html



背景:我包含一些页面元素在一个页面上,一些在500.html被调用时丢失,并且想要在开发环境中进行调试。

解决方案

我不想关闭DEBUG。而是将以下代码片段放在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视图轻松替换它。



现在,您可以通过调用其网址来测试500和404页: http://example.com/500 http://example.com/404


I am using Django for a project and is already in production.

In the production environment 500.html is rendered whenever a server error occurs.

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

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.

解决方案

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'}),
    )

In the snippet above, the error page uses a custom view, you can easily replace it with Django's direct_to_template view though.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆