Fixed #21221 -- Made form Media and static template tag use staticfiles if installed.

This commit is contained in:
Johannes Hoppe 2015-11-07 12:24:38 +01:00 committed by Tim Graham
parent 6be9589eb3
commit cf546e11ac
34 changed files with 145 additions and 144 deletions

View file

@ -203,12 +203,13 @@ Paths in asset definitions
Paths used to specify assets can be either relative or absolute. If a
path starts with ``/``, ``http://`` or ``https://``, it will be
interpreted as an absolute path, and left as-is. All other paths will
be prepended with the value of the appropriate prefix.
be prepended with the value of the appropriate prefix. If the
:mod:`django.contrib.staticfiles` app is installed, it will be used to serve
assets.
As part of the introduction of the
:doc:`staticfiles app </ref/contrib/staticfiles>` two new settings were added
to refer to "static files" (images, CSS, JavaScript, etc.) that are needed
to render a complete web page: :setting:`STATIC_URL` and :setting:`STATIC_ROOT`.
Whether or not you use :mod:`django.contrib.staticfiles`, the
:setting:`STATIC_URL` and :setting:`STATIC_ROOT` settings are required to
render a complete web page.
To find the appropriate prefix to use, Django will check if the
:setting:`STATIC_URL` setting is not ``None`` and automatically fall back
@ -238,6 +239,18 @@ But if :setting:`STATIC_URL` is ``'http://static.example.com/'``::
<script type="text/javascript" src="http://static.example.com/animations.js"></script>
<script type="text/javascript" src="http://othersite.com/actions.js"></script>
Or if :mod:`~django.contrib.staticfiles` is configured using the
`~django.contib.staticfiles.ManifestStaticFilesStorage`::
>>> w = CalendarWidget()
>>> print(w.media)
<link href="/css/pretty.css" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="https://static.example.com/animations.27e20196a850.js"></script>
<script type="text/javascript" src="http://othersite.com/actions.js"></script>
.. versionchanged:: 1.10
Older versions didn't serve assets using :mod:`django.contrib.staticfiles`.
``Media`` objects
-----------------