Search code examples
djangonginxhttp-status-code-500

Displaying image in 500 status page (Django)


I have a Django app with nginx as a reverse proxy web server. I want to serve an image in my 500 error page. How do I do that within a Django project?


I tried the advice here. I.e. my virtual host file for nginx contains:

error_page 500 502 503 504 /500.html;
location = /500.html {
    root /home/myuser/myproject/myapp/templates/;
}

location = /500.png {
    root /home/myuser/myproject/myapp/static/img/;
}

Note that 500.png is indeed placed at /home/myuser/myproject/myapp/static/img/500.png.The HTML template refers to the 500 error image like so:

<img src="500.png" alt=".">

But, although the 500 error page loads correctly, the image itself never loads, falling back to alt in the img tag. What could I be doing wrong? Please ask for more information in case you need it.


Solution

  • You're trying to load a 500.png image on the current dir.

    Change to:

    <img src="/500.png" alt=".">