Reputation: 47
The 500 error handler template won't load CSS even if typed everything correctly. For example, my home template loads CSS properly using the same method Here's the 500.html template
<html>
<head>
{%load static%}
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>500</title>
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}"/>
</head>
<body>
html code here
</body>
</html>
This should load the style.css file from the static folder
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}"/>
In the terminal it looks like everything is OK, but it still doesn't load.
"GET /static/style.css HTTP/1.1" 200 734
if I try to access 127.0.0.1:8000/static/main.css (the one for the homepage) it shows it how it should
if I try to access 127.0.0.1:8000/static/style.css it gives me an error
I don't know if it matters but I'm doing this with DEBUG = False
Edit: I solved the error by running the server with py manage.py runserver --insecure
At this point I wonder how could I get around this if I wanted to host the website on a server? Why doesn't it load static files for error pages without running the server like that?
Upvotes: 2
Views: 916
Reputation: 91
Keep DEBUG=TRUE in setting.py
Documentation: https://docs.djangoproject.com/en/3.2/ref/settings/
Static files are served via Django on when DEBUG is True.
Upvotes: 0
Reputation: 1843
The manage.py runserver
command starts the Django development server, a server which it is not intended to be used in production and which, as a result, stops to serve the static files when DEBUG=FALSE
.
As you point out in your edit, you can bypass this security by using the --insecure
option when you start the server (see the documentation here). But this is clearly an insecure and inefficient solution.
So you can serve the static files with a real HTTP server (some examples and tutorials are given here) or you can have a look to the very popular WhiteNoise application to help you doing that.
Upvotes: 3
Reputation: 123
this is usually i render django template tags : {% load static %}. sometimes pay attention to spaces. and also, I include static on the top of the page.
Upvotes: 0