Résolue

Problème d'intégration de CSS dans Django

# Django # CSS

Jean-Philippe MOLL HEGER

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 !

Jean-Philippe MOLL HEGER

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

Gabriel Trouvé

Mentor

Tu peux me faire une capture de ton arborescence de dossiers et fichiers stp ?

Jean-Philippe MOLL HEGER

Gabriel Trouvé

Mentor

Tu aurais un repo github que je me rende compte ?
Il y a sûrement un truc tout bête, mais comme ça j'ai du mal à voir.

Merci d'avance !

Jean-Philippe MOLL HEGER

Non hélas mon github ne fonctionne à cause d'un ancien compte et je n'arrive pas à push le code.

Jean-Philippe MOLL HEGER

en fait je crois avoir réussi à mettre sur github ... ce lien te suffit ? 'https://github.com/jeanfimollheger/finance.git/

Corrigé ! :)

STATICFILES_DIRS = [BASE_DIR / 'static']
Faillait juste rajouter le "s" à DIR

Jean-Philippe MOLL HEGER

oeil de lynx ! Merci !!! et en plus tu m'as obligé à retourner sut github pour gérer un autre problème ;-)

Gabriel Trouvé

Mentor

C'est super en tous cas ! De rien :)

Bonne soirée

Inscris-toi

(c'est gratuit !)

Inscris-toi

Tu dois créer un compte pour participer aux discussions.

Créer un compte

Rechercher sur le site

Formulaire de contact

Inscris-toi à Docstring

Pour commencer ton apprentissage.

Tu as déjà un compte ? Connecte-toi.