Outils pour utilisateurs

Outils du site


python:django:statics

Statics

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>
python/django/statics.txt · Dernière modification: 2023/11/08 21:36 par marclebrun