Django staticfiles app help

后端 未结 5 1394
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 18:36

I\'ve having a little issue with Django\'s staticfiles app.

I have added

\'django.contrib.staticfiles\',

to my INSTALLED_APPS and

5条回答
  •  时光说笑
    2020-11-28 19:22

    I implore you to read the howto docs here: http://docs.djangoproject.com/en/dev/howto/static-files/

    In short: STATIC_ROOT is only used if you call the collectstatic manangement command. It's not needed to add the directory to the STATICFILES_DIRS setting to serve your static files!

    During development (when the automatic serving view is used) staticfiles will automatically look for static files in various locations (because you call its "serve" view with a path to a static file). For this search it'll use the so called "finders" (as defined in the STATICFILES_FINDERS setting).

    1. One of the default finders is the AppDirectoriesFinder, which will look in the "/static/" directory of each of the apps of yours INSTALLED_APPS setting.

    2. Another default finder is the FileSystemFinder, which will look in directories you specify in the STATICFILES_DIRS setting.

    BTW, both these search patterns are similar to how template loading works.

    The same technique will be used when running the collectstatic command, except that it now will collect the files from the various locations (using the same finders as above), putting the found files into STATIC_ROOT, ready for deployment.

提交回复
热议问题