Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
Staticfiles : tout ce qu'il faut savoir, rien que ce qu'il faut savoir
Bruno Renié
April 14, 2012
Programming
4
490
Staticfiles : tout ce qu'il faut savoir, rien que ce qu'il faut savoir
Bruno Renié
April 14, 2012
Tweet
Share
More Decks by Bruno Renié
See All by Bruno Renié
brutasse
3
390
brutasse
1
130
brutasse
17
2.1k
brutasse
21
2.3k
brutasse
9
1.5k
brutasse
4
510
brutasse
3
360
Other Decks in Programming
See All in Programming
yosuke_furukawa
PRO
1
520
fancyweb
1
100
thatjeffsmith
0
1.6k
o0h
PRO
0
380
xrdnk
0
160
quannt
1
110
hyodol2513
2
1.2k
techharmony
0
210
mrtc0
1
250
minodriven
38
29k
wafuwafu13
1
180
shiba6v
0
210
Featured
See All Featured
jnunemaker
PRO
40
4.7k
zenorocha
298
40k
maggiecrowley
10
560
mza
80
4.2k
malarkey
193
8.7k
paulrobertlloyd
71
3.7k
sstephenson
146
12k
matthewcrist
73
7.5k
dotmariusz
94
5.5k
garrettdimon
289
110k
tmm1
61
9.9k
shlominoach
176
7.6k
Transcript
Staticfiles tout rien que ce qu'il faut savoir Bruno Renié
Djangocong 2012
Django >= 1.4 django-staticfiles >= 1.2
MEDIA STATIC données dynamiques données statiques wat
STATIC_ROOT STATIC_URL STATICFILES_FINDERS STATICFILES_DIRS STATICFILES_STORAGE django-admin.py collectstatic
STATIC_ROOT STATIC_URL STATICFILES_FINDERS STATICFILES_DIRS STATICFILES_STORAGE django-admin.py collectstatic
Layout project/ app1/static/style.css app2/static/jquery.js app1 static app2 static
Configuration minimale # settings.py STATIC_URL = '/static/' # urls.py from
django.contrib.staticfiles.urls \ import staticfiles_urlpatterns urlpatterns += staticfiles_urlpatterns() # settings.py # urls.py
et c'est tout
Référencer un fichier {% load staticfiles %} {% static "jquery.js"
%} staticfiles static
app1/static/foo.css app2/static/foo.css {% static "foo.css" %} Conflits Comme les templates
foo.css foo.css "foo.css"
Namespaces Applications réutilisables / éviter les conflits app1/static/app1/foo.css app2/static/app2/foo.css {%
static "app2/foo.css" %} app1/foo.css app2/foo.css "app2/foo.css"
STATICFILES_DIRS Applications non-standard
En production # settings.py STATIC_ROOT = '/path/to/public/static' $ python manage.py
collectstatic # settings.py
et c'est tout
Cache busting STATICFILES_STORAGE = ( 'django.contrib.' 'staticfiles.storage.' 'CachedStaticFilesStorage' ) {%
static "foo.css" %} ↓ /static/foo.1cc9fe7eb4b9.css
{% static %} ♡ @brutasse