djangodjango-templatesdjango-viewsdjango-extensions

django- how to address static files in 404.html template



according to django's documentation:

When you raise Http404 from within a view, Django loads a special view devoted to handling 404 errors. By default, it’s the view django.views.defaults.page_not_found(), which either produces a very simple “Not Found” message or loads and renders the template 404.html if you created it in your root template directory.

, i created a 404.html file in the root template directory. when the app raises a 404 error, this 404.html that i created before, will shown, but it's css and it's background image not load.

this is the 404.html file code:

<!DOCTYPE html>{% load staticfiles %}
<html>
<head>
    <title>not found</title>
    <link rel="stylesheet" href="{% static 'css/error_style.css' %}"/>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
</head>
<body class="color-404">
<div id="error">
    <img class="error-image" src="{% static 'img/404.jpg' %}"/>
</div>
<div class="error-router">
    <a href="#" class="gohome"><i class="fa fa-home"></i></a>
    <a href="" onclick="window.history.back();" class="goback"><i class="fa fa-arrow-left"></i></a>
</div>
</body>
</html>

how can i fix this problem? tanx


Solution

  • I found what was the problem. because i set DEBUG to False, django's built-in webserver, was not served staticfiles.