can someone help me why my static files is not being rendered?

62 views
Skip to first unread message

Aspersh Upadhyay

unread,
Jun 15, 2023, 9:33:06 AM6/15/23
to Django users
my settings.py 

STATIC_URL = 'static/'

STATICFILES_DIR = [
    BASE_DIR / "static"
]

Template where I am trying to load static files

{% extends 'base.html' %}
{% load static %}

{% block title %}
  Issue With Django static files
{%endblock title %}
{% block body %}
<body class="bg-gray-50 font-serif leading-normal tracking-normal">
      <div class="lg:max-w-lg lg:w-full md:w-1/2 w-5/6 mb-10 md:mb-0">
        <img class="object-cover object-center rounded" alt="hero"
src="{% static 'Python.png' %}">
      </div>
</body>

terminal throwing me 404 see this 👇👇

"GET /static/Python.png HTTP/1.1" 404 1789

I hope here I will get my solution for this.

Prosper Lekia

unread,
Jun 15, 2023, 9:53:38 AM6/15/23
to django...@googlegroups.com
Where is the Python.png located?

From your code, it should be directly in your static folder not a subfolder. So verify your file structure first. If every is in order, confirm if whitenoise is installed, and been added to your MiddleWare.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/54b813cc-58f4-4cbe-80af-a427f063fbb2n%40googlegroups.com.

ALBERT ASHABA AHEEBWA

unread,
Jun 15, 2023, 10:47:32 AM6/15/23
to django...@googlegroups.com
According to your settings, the `Python.png` file should be inside `static` on the same level as `manage.py`.

|---static /
     |-- Python.png
|--manage.py
|--....

The file structure of almost that kind. If you're in development and this is a practice thing, you don't need `whitenoise` just yet.

Ngaga Dancan

unread,
Jun 15, 2023, 10:53:05 AM6/15/23
to django...@googlegroups.com
Use load static first before you use extends 


Makan Dianka

unread,
Jun 15, 2023, 11:30:20 PM6/15/23
to django...@googlegroups.com
It is :

STATICFILES_DIRS=[
     .....
]

Not :

STATICFILES_DIR=[
     .....
]

Just add S in the end of DIR like DIRS and make sur u create static folder in your project root.


Aspersh Upadhyay

unread,
Jun 16, 2023, 2:30:56 AM6/16/23
to Django users
Thanks a lot to Makan Dianka and everyone who replied to my question. Your help was greatly appreciated. I was able to solve the problem using Makan Dianka's solution.

Mohammad Sadegh

unread,
Jun 17, 2023, 10:09:55 AM6/17/23
to django...@googlegroups.com
Yes send message to my account
Reply all
Reply to author
Forward
0 new messages