Search code examples
htmlcssdjangostatic

base.css does not apply in Django project


I have a following structure of my folders:

folder structure

And I try to import the base.css to base.html so that it applies everywhere:

MY HTML:

<!DOCTYPE html>
{% load static %}
<html>
  <head>
    <link rel="stylesheet" href="{% static 'base.css' %}">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  (...)
</html>

MY SETTINGS:

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR,'static')

Tried different combinations, but nothing seems to work. Please help :)


Solution

  • A'ight managed to fix it after yet another rendez-vous with documentation, but not in the most elegant way.

    I changed the settings.py to:

    STATIC_URL = "static/"
    
    STATICFILES_DIRS = [
        BASE_DIR / "static",
    ]
    

    Now it works fine, but as I said, it doesn't look very Django to me. If anyone finds a better approach, please share it.