{% get_media_prefix %} Tag

puts MEDIA_URL into the template.

Utility As Markdown

Argument(s)
as varname (optional)
Closing tag
Not required
Requires
{% load static %}

Documentation

The MEDIA_URL counterpart to get_static_prefix, for uploaded files rather than the ones you ship.

Template

{% load static %}
<script>const MEDIA = "{% get_media_prefix %}";</script>

Result

<script>const MEDIA = "/media/";</script>

For a FileField you almost always want {{ obj.file.url }} instead, which already includes the prefix.

More Utility Tags

All Utility Tags


Did we get something wrong? Is there a use case for the get_media_prefix tag that we should add? Please let us know.

Send Feedback

Official Documentation
This page last updated on August 20, 2026