django官方文件關於STATIC_URL STATIC_ROOT STATICFILES_DORS collectstatic的描述
https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-STATIC_ROOT
STATIC_ROOT
¶
Default: None
The absolute path to the directory where collectstatic
will
collect static files for deployment.
Example: "/var/www/example.com/static/"
If the staticfiles contrib app is enabled (as in the default
project template), the collectstatic
management
command will collect static files into this directory. See the how-to on managing static files for more details
about usage.
Warning
This should be an initially empty destination directory for collecting your static files from their permanent locations into one directory for ease of deployment; it is not
finders
,
which by default, are 'static/'
app sub-directories and any directories you include
in STATICFILES_DIRS
).
STATIC_URL
¶
Default: None
URL to use when referring to static files located in STATIC_ROOT
.
Example: "/static/"
or "http://static.example.com/"
If not None
, this will be used as the
base path for asset definitions (the Media
class)
and the staticfiles app.
It must end in a slash if set to a non-empty value.
STATICFILES_DIRS
¶
Default: []
(Empty list)
This setting defines the additional locations the staticfiles app will traverse if the FileSystemFinder
finder
is enabled, e.g. if you use thecollectstatic
or findstatic
management
command or use the static file serving view.
This should be set to a list 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", ]
Note that these paths should use Unix-style forward slashes, even on Windows (e.g."C:/Users/user/mysite/extra_static_content"
).
Prefixes (optional)¶
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"), ]
For example, assuming you have STATIC_URL
set
to '/static/'
, the collectstatic
management
command would collect the “stats” files in a 'downloads'
subdirectory of STATIC_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 "downloads/polls_20101022.tar.gz" %}">
https://docs.djangoproject.com/en/1.11/ref/contrib/staticfiles/
Management Commands¶
django.contrib.staticfiles
exposes three management commands.
collectstatic
¶
-
django-admin collectstatic
¶
Collects the static files into STATIC_ROOT
.