Search code examples
djangostatichttp-status-code-404

Django static files 404 errors just for one folder and all images


Edit The syntax error fix provided by willeM_ Van Onsem fixed the addition of characters to the path of the image. Now they are just normal 404 errors :).

And with those fixed, python returns more 404 errors so I see that there is nothing unique about the daterangepicker folder


Original

I'm integrating a theme into my project. Some of the static files are found, but I get two types 404 errors. I'd appreciate any help.

The first type (all images):

For the line

<img class="rounded-circle" src="{% static 'sleek-bootstrap/source/assets/img/user/u6.jpg" alt="Image' %}">

I get the error

"GET /static/sleek-bootstrap/source/assets/img/user/u6.jpg%22%20alt%3D%22Image 404 1958

The file /static/sleek-bootstrap/source/assets/img/user/u6.jpg does exist, but somehow Django adds %22%20alt%3D%22Image to the name, so of course it can't find it. It does this for all the image files in the template

The second type (one folder):

for the line

    <script src="{% static 'sleek-bootstrap/source/assets/plugins/daterangepicker/moment.min.js' %}"> ></script>

I get the error "GET /static/sleek-bootstrap/source/assets/plugins/daterangepicker/moment.min.js HTTP/1.1" HTTP/1.1" 404 1958

Django finds all the files in the path /static/sleek-bootstrap/source/assets/plugins/, except those in the daterangepicker plugin folder.


Solution

  • You closed to template tag too late:

    <img class="rounded-circle" src="{% static 'sleek-bootstrap/source/assets/img/user/u6.jpg" %} alt="Image">

    By using {% static 'some-img" alt="text' %}"', you included the alt=` attribute in the name of the file, and this then returns a 404.