0

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.

Hassan Baig
  • 15,055
  • 27
  • 102
  • 205

3 Answers3

1
{% load static %}
<img src="{% static 'img/500.png' %}" alt=".">
Exprator
  • 26,992
  • 6
  • 47
  • 59
1

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

Change to:

<img src="/500.png" alt=".">
sergiogarciadev
  • 2,061
  • 1
  • 21
  • 35
0

Try removing the trailing slash in the img url,

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; 
            }
zaidfazil
  • 9,017
  • 2
  • 24
  • 47