A
A
Anton2021-10-05 21:49:30
Django
Anton, 2021-10-05 21:49:30

Django doesn't see static files in folder. Why?

I was faced with a problem when django can't see static files and I'm getting 404 error every time visiting the page.

[05/Oct/2021 19:25:07] "GET /static/main/css/index.css HTTP/1.1" 404 1813


Here is my setting.py
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/


STATIC_URL = '/static/'

STATICFILES_DIRS = ( os.path.join('static'), )

# Default primary key field type


Another part was cut

HTML file
{% load static %}
<!DOCTYPE html>


<html>
<head>
    <meta charset="utf-8" />
    <title>Hello World</title>
    <link rel="stylesheet"  href="{% static 'main/css/index.css' %}" />
</head>

Another part was cut too

Project folder:
615c9e046e43c529782334.png

urls.py
from django.urls import path, include
from . import views

urlpatterns = [
    path('', views.index),
    path('about', views.about)
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Mokhovikov, 2021-10-06
@goozzy

Try to fix on:

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]

But it will be better if you read the documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question