Django provides template tags and filters to control each aspect of internationalization in templates. They allow for granular control of translations, formatting, and time zone conversions.
This library allows specifying translatable text in templates. To enable it, set USE_I18N to True, then load it with{% load i18n %}.
See Internationalization: in template code.
This library provides control over the localization of values in templates. You only need to load the library using{% load l10n %}, but youll often set USE_L10N to True so that localization is active by default.
See Controlling localization in templates.
This library provides control over time zone conversions in templates. Like l10n, you only need to load the library using{% load tz %}, but youll usually also set USE_TZ to True so that conversion to local time happens by default.
Django comes with a couple of other template-tag libraries that you have to enable explicitly in your INSTALLED_APPS setting and enable in your template with the {% load %} tag.
A set of Django template filters useful for adding a human touch to data. See django.contrib.humanize.
A collection of template tags that can be useful while designing a Web site, such as a generator of Lorem Ipsum text. Seedjango.contrib.webdesign.
To link to static files that are saved in STATIC_ROOT Django ships with a static template tag. You can use this regardless if youre using RequestContext or not.
{% load static %} <img src="{% static "images/hi.jpg" %}" alt="Hi!" />
It is also able to consume standard context variables, e.g. assuming a user_stylesheet variable is passed to the template:
{% load static %} <link rel="stylesheet" href="{% static user_stylesheet %}" type="text/css" media="screen" />
If youd like to retrieve a static URL without displaying it, you can use a slightly different call:
.. versionadded:: 1.5
{% load static %} {% static "images/hi.jpg" as myphoto %} <img src="{{ myphoto }}"></img>
Note
The staticfiles contrib app also ships with a static template tag which uses staticfiles'STATICFILES_STORAGE to build the URL of the given path (rather than simply using urlparse.urljoin() with theSTATIC_URL setting and the given path). Use that instead if you have an advanced use case such as using a cloud service to serve static files:
{% load static from staticfiles %} <img src="{% static "images/hi.jpg" %}" alt="Hi!" />
If youre not using RequestContext, or if you need more control over exactly where and how STATIC_URL is injected into the template, you can use the get_static_prefix template tag instead:
{% load static %} <img src="{% get_static_prefix %}images/hi.jpg" alt="Hi!" />
Theres also a second form you can use to avoid extra processing if you need the value multiple times:
{% load static %} {% get_static_prefix as STATIC_PREFIX %} <img src="{{ STATIC_PREFIX }}images/hi.jpg" alt="Hi!" /> <img src="{{ STATIC_PREFIX }}images/hi2.jpg" alt="Hello!" />
Similar to the get_static_prefix, get_media_prefix populates a template variable with the media prefix MEDIA_URL, e.g.:
<script type="text/javascript" charset="utf-8"> var media_path = '{% get_media_prefix %}'; </script>
Product: DataEase for Windows 7.x. Written by George Washington 11/04/14 at 08:26:17
Product: DataEase 8 Reporter. Written by eduardo paez 02/05/14 at 14:40:11
Product: . Written by Marco Marchesi 15/02/16 at 14:50:46
Product: . Written by Grossi Gioacchino 18/11/19 at 14:33:44
Product: Dataease [{8}]FIVE. Written by Rainer 22/03/21 at 11:13:10
Product: Dataease [{8}]FIVE. Written by Rainer 08/06/21 at 14:12:40