A glance at Django static files


to configure

1. InINSTALLED_APPSConfirm that the setting item containsdjango.contrib.staticfiles
2. IncreaseSTATIC_URLSetting item. The value is a string (path) and must end with ‘/’
3. Reference in the template:

python{% load staticfiles %}

4. On the appstaticDirectory to store static files


Used during development
Extremely inefficient
DeployingThere are other ways to do it
be carefulnamespacing


Default to[], a list indicating the storage location of static files independent of app.


  • django.contrib.staticfiles.finders.FileSystemFinder
    According to staticfiles_ The path indicated by dirs searches for files

  • django.contrib.staticfiles.finders.AppDirectoriesFinder
    Search for files in the static directory of the app

  • django.contrib.staticfiles.finders.DefaultStorageFInder
    Not enabled by default, according to default_ FILE_ The path indicated by storage searches for files

“First match principle”


Use the finder to find the specified static file
--firstOption: display only the first matching
--verbosity [0/1/2]: when the value is 0, no redundant information will be prompted, and when the value is 2, the directory will also be output.