Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django media url is not resolved in 500 internal server error template

Tags:

django

I'm using a 500.html template for my app, which is an identical copy of the 404.html with some minor text changes.

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.

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

like image 767
Thomas Kremmel Avatar asked Apr 05 '10 17:04

Thomas Kremmel


1 Answers

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.

You can set your own 500 handler and pass a RequestContext if you want.

Here's a link to the django docs on making a custom handler500.

like image 73
Seth Avatar answered Oct 07 '22 18:10

Seth