1
0
mirror of https://github.com/django/django.git synced 2024-12-27 03:25:58 +00:00

[1.8.x] Improved get_media_prefix template tag example.

Backport of 9a4a9a8a49 from master
This commit is contained in:
Aymeric Augustin 2015-03-05 09:13:56 -05:00 committed by Tim Graham
parent 3bc35f7e08
commit 2bef57f3fb

View File

@ -2620,6 +2620,8 @@ get_media_prefix
Similar to the :ttag:`get_static_prefix`, ``get_media_prefix`` populates a Similar to the :ttag:`get_static_prefix`, ``get_media_prefix`` populates a
template variable with the media prefix :setting:`MEDIA_URL`, e.g.:: template variable with the media prefix :setting:`MEDIA_URL`, e.g.::
<script type="text/javascript" charset="utf-8"> {% load static %}
var media_path = '{% get_media_prefix %}'; <body data-media-url="{% get_media_prefix %}">
</script>
By storing the value in a data attribute, we ensure it's escaped appropriately
if we want to use it in a JavaScript context.