diff options
| author | Johannes Hoppe <info@johanneshoppe.com> | 2015-11-07 12:24:38 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-12-10 14:30:19 -0500 |
| commit | cf546e11ac76c8dec527e39ff8ce8249a195ab42 (patch) | |
| tree | c86d039e94099e47382bbeaf4361fef22bbcf55e /docs/ref | |
| parent | 6be9589eb34f79914666c9d9e1e15bdb7fc44df2 (diff) | |
Fixed #21221 -- Made form Media and static template tag use staticfiles if installed.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/contrib/admin/javascript.txt | 4 | ||||
| -rw-r--r-- | docs/ref/contrib/staticfiles.txt | 52 | ||||
| -rw-r--r-- | docs/ref/templates/builtins.txt | 23 |
3 files changed, 24 insertions, 55 deletions
diff --git a/docs/ref/contrib/admin/javascript.txt b/docs/ref/contrib/admin/javascript.txt index b517aa18cc..8b14b781c9 100644 --- a/docs/ref/contrib/admin/javascript.txt +++ b/docs/ref/contrib/admin/javascript.txt @@ -26,7 +26,7 @@ In your custom ``change_form.html`` template, extend the .. code-block:: html+django {% extends 'admin/change_form.html' %} - {% load admin_static %} + {% load static %} {% block admin_change_form_document_ready %} {{ block.super }} @@ -65,7 +65,7 @@ namespace, just listen to the event triggered from there. For example: .. code-block:: html+django {% extends 'admin/change_form.html' %} - {% load admin_static %} + {% load static %} {% block admin_change_form_document_ready %} {{ block.super }} diff --git a/docs/ref/contrib/staticfiles.txt b/docs/ref/contrib/staticfiles.txt index 010eacccce..e6caa53e32 100644 --- a/docs/ref/contrib/staticfiles.txt +++ b/docs/ref/contrib/staticfiles.txt @@ -285,11 +285,16 @@ following requirements are met: * the :setting:`STATICFILES_STORAGE` setting is set to ``'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'`` * the :setting:`DEBUG` setting is set to ``False`` -* you use the ``staticfiles`` :ttag:`static<staticfiles-static>` template - tag to refer to your static files in your templates * you've collected all your static files by using the :djadmin:`collectstatic` management command +.. versionchanged:: 1.10 + + In older versions, you also had to use + ``{% load static from staticfiles %}`` in your template. The + :ttag:`static` template tag (``{% load static %}``) now uses + :mod:`django.contrib.staticfiles` if it's installed. + Since creating the MD5 hash can be a performance burden to your website during runtime, ``staticfiles`` will automatically store the mapping with hashed names for all processed files in a file called ``staticfiles.json``. @@ -331,43 +336,6 @@ If you want to override certain options of the cache backend the storage uses, simply specify a custom entry in the :setting:`CACHES` setting named ``'staticfiles'``. It falls back to using the ``'default'`` cache backend. -.. currentmodule:: django.contrib.staticfiles.templatetags.staticfiles - -Template tags -============= - -static ------- - -.. templatetag:: staticfiles-static - -Uses the configured :setting:`STATICFILES_STORAGE` storage to create the -full URL for the given relative path, e.g.: - -.. code-block:: html+django - - {% load static from staticfiles %} - <img src="{% static "images/hi.jpg" %}" alt="Hi!" /> - -The previous example is equal to calling the ``url`` method of an instance of -:setting:`STATICFILES_STORAGE` with ``"images/hi.jpg"``. This is especially -useful when using a non-local storage backend to deploy files as documented -in :ref:`staticfiles-from-cdn`. - -If you'd like to retrieve a static URL without displaying it, you can use a -slightly different call: - -.. code-block:: html+django - - {% load static from staticfiles %} - {% static "images/hi.jpg" as myphoto %} - <img src="{{ myphoto }}" alt="Hi!" /> - -.. admonition:: Using Jinja2 templates? - - See :class:`django.template.backends.jinja2.Jinja2` for information on - using the ``static`` tag with Jinja2. - Finders Module ============== @@ -390,8 +358,10 @@ files: which adds :setting:`STATIC_URL` to every template context rendered with :class:`~django.template.RequestContext` contexts. -- The builtin template tag :ttag:`static` which takes a path and - urljoins it with the static prefix :setting:`STATIC_URL`. +- The builtin template tag :ttag:`static` which takes a path and urljoins it + with the static prefix :setting:`STATIC_URL`. If + ``django.contrib.staticfiles`` is installed, the tag uses the ``url()`` + method of the :setting:`STATICFILES_STORAGE` instead. - The builtin template tag :ttag:`get_static_prefix` which populates a template variable with the static prefix :setting:`STATIC_URL` to be diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt index 680f9eda9b..da6df4472f 100644 --- a/docs/ref/templates/builtins.txt +++ b/docs/ref/templates/builtins.txt @@ -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? + + See :class:`~django.template.backends.jinja2.Jinja2` for information on + using the ``static`` tag with Jinja2. - 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>`:: +.. versionchanged:: 1.10 - {% load static from staticfiles %} - <img src="{% static "images/hi.jpg" %}" alt="Hi!" /> + 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 |
