I'm using a 500.html template for my app, which is an identical copy of the 404.html with some minor text changes.
我正在为我的应用程序使用500.html模板,这是404.html的相同副本,其中包含一些小的文本更改。
Interestingly the {{ media_url }} context variable will not be resolved by the server if the 500.html is presented (e.g. when I force an internal server error), resulting in a page without any css loaded.
有趣的是,如果显示500.html(例如,当我强制内部服务器出错时),服务器将无法解析{{media_url}}上下文变量,从而导致页面没有加载任何css。
An easy way to circumvent this would be to hardcode the links to the css, but I m just curious why the media_url is not resolved. Probably it is because the server encounters a internal server error and that leads to context variables not any more available!?
避免这种情况的一种简单方法是将链接硬编码到css,但我只是好奇为什么media_url没有得到解决。可能是因为服务器遇到内部服务器错误,导致上下文变量不再可用!?
2 个解决方案
#1
11
The 500 error handler doesn't pass a RequestContext
to the template, it just uses a Context
. As you may know, MEDIA_URL
is added in a context processor, which are only included when you use a RequestContext
.
500错误处理程序不会将RequestContext传递给模板,它只使用Context。您可能知道,MEDIA_URL是在上下文处理器中添加的,只有在使用RequestContext时才会包含它。
You can set your own 500 handler and pass a RequestContext if you want.
如果需要,您可以设置自己的500处理程序并传递RequestContext。
Here's a link to the django docs on making a custom handler500.
这是关于制作自定义处理程序500的django文档的链接。
#2
3
The django docs recommend that you do not use a template for your 500.html file because there is no way of dealing with an error in the rendering of that template.
django文档建议您不要为500.html文件使用模板,因为在呈现该模板时无法处理错误。
Just stick with a straight HTML file informing the user that there has been an error. That's all they need to know.
只需坚持使用直接的HTML文件,通知用户出现了错误。这就是他们需要知道的全部内容。
You can look at the server logs for what you need to know.
您可以查看服务器日志以了解您需要了解的内容。
#1
11
The 500 error handler doesn't pass a RequestContext
to the template, it just uses a Context
. As you may know, MEDIA_URL
is added in a context processor, which are only included when you use a RequestContext
.
500错误处理程序不会将RequestContext传递给模板,它只使用Context。您可能知道,MEDIA_URL是在上下文处理器中添加的,只有在使用RequestContext时才会包含它。
You can set your own 500 handler and pass a RequestContext if you want.
如果需要,您可以设置自己的500处理程序并传递RequestContext。
Here's a link to the django docs on making a custom handler500.
这是关于制作自定义处理程序500的django文档的链接。
#2
3
The django docs recommend that you do not use a template for your 500.html file because there is no way of dealing with an error in the rendering of that template.
django文档建议您不要为500.html文件使用模板,因为在呈现该模板时无法处理错误。
Just stick with a straight HTML file informing the user that there has been an error. That's all they need to know.
只需坚持使用直接的HTML文件,通知用户出现了错误。这就是他们需要知道的全部内容。
You can look at the server logs for what you need to know.
您可以查看服务器日志以了解您需要了解的内容。