Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django cant find static files 404error

I’m using django to create apps in the project.
I’m going to make common files into templates and static folders under the project folder of the project. However, when the server is running, the files in the templates are found well, but the files in the static folder are not imported.
I tried a few attempts through a search, but it didn’t work, so I ask questions. I would appreciate an answer.

setting.py

STATIC_URL = '/static/'
STATIC_DIRS = [
    os.path.join(BASE_DIR, 'static'),
    # BASE_DIR / 'static',
]
# STATIC_ROOT = os.path.join(BASE_DIR, 'assets')

my folder structure

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

project
-app1
-app2
-templates
  -app1
    -index.html
  -app2
    -index.html
-static
  -style.css
  -app.js

html code

{% load static %}
<link href="{% static 'style.css' %}" rel="stylesheet" />

>Solution :

There is a typo in settings.py.

Instead of:

STATIC_DIRS = [
    os.path.join(BASE_DIR, 'static'),
    # BASE_DIR / 'static',
]

Write this:

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
    # BASE_DIR / 'static',
]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading