Settings¶
-
django.conf.settings.
STATIC_ROOT
¶ Default: ""
(Empty string)The absolute path to the directory that contains static content after using collectstatic.
Example:
"/home/example.com/static/"
When using the collectstatic management command this will be used to collect static files into, to be served under the URL specified as
STATIC_URL
.This is a required setting to use collectstatic – unless you’ve overridden
STATICFILES_STORAGE
and are using a custom storage backend.Warning
This is not a place to store your static files permanently under version control!
You should do that in directories that will be found by your
STATICFILES_FINDERS
(by default, per-app'static'
subdirectories, and any directories you include inSTATICFILES_DIRS
setting). Files from those locations will be collected intoSTATIC_ROOT
.See also
STATIC_URL
.
-
django.conf.settings.
STATIC_URL
¶ Default: None
URL that handles the files served from
STATIC_ROOT
and used byrunserver
in development mode (whenDEBUG = True
).Example:
"/site_media/static/"
or"http://static.example.com/"
It must end in a slash if set to a non-empty value.
See also
STATIC_ROOT
.
-
django.conf.settings.
STATICFILES_DIRS
¶ Default: ()
This setting defines the additional locations the staticfiles app will traverse if the
FileSystemFinder
finder is enabled, e.g. if you use the collectstatic or findstatic management command or use the static file serving view.This should be set to a list or tuple of strings that contain full paths to your additional files directory(ies) e.g.:
STATICFILES_DIRS = ( "/home/special.polls.com/polls/static", "/home/polls.com/polls/static", "/opt/webfiles/common", )
In case you want to refer to files in one of the locations with an additional namespace, you can OPTIONALLY provide a prefix as
(prefix, path)
tuples, e.g.:STATICFILES_DIRS = ( # ... ("downloads", "/opt/webfiles/stats"), )
Example:
Assuming you have
STATIC_URL
set'/static/'
, the collectstatic management command would collect the stats files in a'downloads'
subdirectory ofSTATIC_ROOT
.This would allow you to refer to the local file
'/opt/webfiles/stats/polls_20101022.tar.gz'
with'/static/downloads/polls_20101022.tar.gz'
in your templates, e.g.:<a href="{{ STATIC_URL }}downloads/polls_20101022.tar.gz">
-
django.conf.settings.
STATICFILES_IGNORE_PATTERNS
¶ Default: ()
This setting defines patterns to be ignored by the collectstatic management command.
This should be set to a list or tuple of strings that contain file or directory names and may include an absolute file system path or a path relative to
STATIC_ROOT
, e.g.:STATICFILES_IGNORE_PATTERNS = ( "*.txt", "tests", "css/*.old", "/opt/webfiles/common/*.txt", "/opt/webfiles/common/temp", )
New in version 1.2.
-
django.conf.settings.
STATICFILES_EXCLUDED_APPS
¶ Default: ()
A sequence of app paths that should be ignored when searching for static files, e.g.:
STATICFILES_EXCLUDED_APPS = ( 'annoying.app', 'old.company.app', )
-
django.conf.settings.
STATICFILES_STORAGE
¶ Default: 'staticfiles.storage.StaticFileStorage'
The file storage engine to use when collecting static files with the collectstatic management command.
-
django.conf.settings.
STATICFILES_FINDERS
¶ Default: ('staticfiles.finders.FileSystemFinder', 'staticfiles.finders.AppDirectoriesFinder')
The list of finder backends that know how to find static files in various locations.
The default will find files stored in the
STATICFILES_DIRS
setting (usingstaticfiles.finders.FileSystemFinder
) and in astatic
subdirectory of each app (usingstaticfiles.finders.AppDirectoriesFinder
)One finder is disabled by default:
staticfiles.finders.DefaultStorageFinder
. If added to yourSTATICFILES_FINDERS
setting, it will look for static files in the default file storage as defined by theDEFAULT_FILE_STORAGE
setting.Note
When using the
AppDirectoriesFinder
finder, make sure your apps can be found by staticfiles. Simply add the app to theINSTALLED_APPS
setting of your site.Static file finders are currently considered a private interface, and this interface is thus undocumented.
To ease the burden of upgrading a Django project from a non-
staticfiles
setup, the optional finder backendstaticfiles.finders.LegacyAppDirectoriesFinder
is shipped as part ofdjango-staticfiles
.When added to the
STATICFILES_FINDERS
setting, it’ll enablestaticfiles
to use themedia
directory of the apps inINSTALLED_APPS
, similarlystaticfiles.finders.AppDirectoriesFinder
.This is especially useful for 3rd party apps that haven’t been switched over to the
static
directory instead. If you want to use bothstatic
andmedia
, don’t forget to havestaticfiles.finders.AppDirectoriesFinder
in theSTATICFILES_FINDERS
, too.