mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #21221 -- Made form Media and static template tag use staticfiles if installed.
This commit is contained in:
parent
6be9589eb3
commit
cf546e11ac
34 changed files with 145 additions and 144 deletions
|
@ -2399,8 +2399,9 @@ static
|
|||
""""""
|
||||
|
||||
To link to static files that are saved in :setting:`STATIC_ROOT` Django ships
|
||||
with a :ttag:`static` template tag. You can use this regardless if you're
|
||||
using :class:`~django.template.RequestContext` or not. For example::
|
||||
with a :ttag:`static` template tag. If the :mod:`django.contrib.staticfiles`
|
||||
app is installed, the tag will serve files using ``url()`` method of the
|
||||
storage specified by :setting:`STATICFILES_STORAGE`. For example::
|
||||
|
||||
{% load static %}
|
||||
<img src="{% static "images/hi.jpg" %}" alt="Hi!" />
|
||||
|
@ -2418,18 +2419,16 @@ slightly different call::
|
|||
{% static "images/hi.jpg" as myphoto %}
|
||||
<img src="{{ myphoto }}"></img>
|
||||
|
||||
.. note::
|
||||
.. admonition:: Using Jinja2 templates?
|
||||
|
||||
The :mod:`staticfiles<django.contrib.staticfiles>` contrib app also ships
|
||||
with a :ttag:`static template tag<staticfiles-static>` which uses
|
||||
``staticfiles'`` :setting:`STATICFILES_STORAGE` to build the URL of the
|
||||
given path (rather than simply using :func:`urllib.parse.urljoin` with the
|
||||
:setting:`STATIC_URL` setting and the given path). Use that instead if you
|
||||
have an advanced use case such as :ref:`using a cloud service to serve
|
||||
static files<staticfiles-from-cdn>`::
|
||||
See :class:`~django.template.backends.jinja2.Jinja2` for information on
|
||||
using the ``static`` tag with Jinja2.
|
||||
|
||||
{% load static from staticfiles %}
|
||||
<img src="{% static "images/hi.jpg" %}" alt="Hi!" />
|
||||
.. versionchanged:: 1.10
|
||||
|
||||
In older versions, you had to use ``{% load static from staticfiles %}`` in
|
||||
your template to serve files from the storage defined in
|
||||
:setting:`STATICFILES_STORAGE`. This is no longer required.
|
||||
|
||||
.. templatetag:: get_static_prefix
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue