Improved get_media_prefix template tag example.

This commit is contained in:
Aymeric Augustin 2015-03-05 09:13:56 -05:00 committed by Tim Graham
parent d61ebc8fed
commit 9a4a9a8a49
1 changed files with 5 additions and 3 deletions

View File

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