Problème d'intégration de CSS dans Django
bonsoir
j'essaie de mettre du css pour la 1ere fois dans django. A la racine mon projet, mon app, mon env,mon template avec le fichier base.html et mon static avec un sous-dossier css qui contient le fichier style.css.
Dans projet.settings.py j'ai bien STATIC_URL = 'static/' et j'ai rajouté (chatgpt) :
STATICFILES_DIRS = [BASE_DIR / 'static']
STATIC_ROOT = [BASE_DIR / 'staticfiles']
dans les fichiers base.html et flux_form.html j'ai rajouté
{% load static %} puis <link href="{% static 'css/style.css' %}" rel="stylesheet"/>mon fichier style.css :
h2 {
text-transform: uppercase;
text-align: center;
}
Dans le flux_form.html j'ai un h2 et bin pas une modif ... merci d'avance !
Salut Jean-Philippe !
Pour ta constante STATIC_ROOT je vois une erreur,
ça ne doit pas être une liste mais :
STATIC_ROOT = BASE_DIR / 'staticfiles'
En faisant cette modification, tu as toujours une erreur ?
Au passage, dans ton static, tu as un fichier css/style.css ? (au niveau arborescence, jsute pour être sûr ^^)
Bonne soirée !
Merci pour ton retour Gab, malgré la correction j'ai toujours la "non-modifiaction" ... il me fait des 404 dans le terminal :
System check identified no issues (0 silenced).
September 10, 2024 - 21:54:29
Django version 4.2.15, using settings 'headquarter.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[10/Sep/2024 21:56:42] "GET / HTTP/1.1" 200 747
[10/Sep/2024 21:56:42] "GET /static/css/style.css HTTP/1.1" 404 1798
[10/Sep/2024 21:56:44] "GET /flux/create/ HTTP/1.1" 200 4527
[10/Sep/2024 21:56:44] "GET /static/css/style.css HTTP/1.1" 404 1798
Inscris-toi
(c'est gratuit !)
Tu dois créer un compte pour participer aux discussions.
Créer un compte

