Par défaut, Django cherche les fichiers statiques dans le dossier static de chaque application.
Dans ce dossier static, un sous-dossier portant le nom de l'application.
./monsite ├── blog │ ├── ... │ ├── static │ │ └── blog │ │ ├── css │ │ │ └── global.css │ │ ├── bootstrap │ │ │ ├── css │ │ │ └── js │ │ └── ... │ ├── templates │ │ └── blog │ │ ├── home.html │ │ └── ... │ └── ... ├── ... └── monsite └── ...
Au début d'un template, ajouter cette instruction :
{% load static %}
Puis pour intégrer les fichiers statiques dans le template :
<head> ... <link rel="stylesheet" href="{% static 'blog/bootstrap-5.0.2/dist/css/bootstrap.min.css' %}"> <link rel="stylesheet" href="{% static 'blog/css/global.css' %}"> </head> <body> ... <script src="{% static 'blog/bootstrap-5.0.2/dist/js/bootstrap.bundle.min.js' %}> </body>