Staticfilestoutrien quece qu'il faut savoirBruno ReniéDjangocong 2012
View Slide
Django >= 1.4django-staticfiles >= 1.2
MEDIASTATICdonnées dynamiquesdonnées statiqueswat
STATIC_ROOTSTATIC_URLSTATICFILES_FINDERSSTATICFILES_DIRSSTATICFILES_STORAGEdjango-admin.py collectstatic
Layoutproject/app1/static/style.cssapp2/static/jquery.jsapp1 staticapp2 static
Configuration minimale# settings.pySTATIC_URL = '/static/'# urls.pyfrom django.contrib.staticfiles.urls \import staticfiles_urlpatternsurlpatterns += staticfiles_urlpatterns()# settings.py# urls.py
et c'esttout
Référencer un fichier{% load staticfiles %}{% static "jquery.js" %}staticfilesstatic
app1/static/foo.cssapp2/static/foo.css{% static "foo.css" %}ConflitsComme les templatesfoo.cssfoo.css"foo.css"
NamespacesApplications réutilisables / éviter les conflitsapp1/static/app1/foo.cssapp2/static/app2/foo.css{% static "app2/foo.css" %}app1/foo.cssapp2/foo.css"app2/foo.css"
STATICFILES_DIRSApplications non-standard
En production# settings.pySTATIC_ROOT = '/path/to/public/static'$ python manage.py collectstatic# settings.py
Cache bustingSTATICFILES_STORAGE = ('django.contrib.''staticfiles.storage.''CachedStaticFilesStorage'){% static "foo.css" %}↓/static/foo.1cc9fe7eb4b9.css
{% static %}♡@brutasse