---
title: '{% get_media_prefix %}'
description: puts MEDIA\_URL into the template.
date: '2026-08-21'
categories:
  - Template Tag
  - Utility
canonical: https://djangotemplatetagsandfilters.com/tags/get_media_prefix/
doc_link: https://docs.djangoproject.com/en/6.1/ref/templates/builtins/#get-media-prefix
---

# {% get_media_prefix %}

puts MEDIA\_URL into the template.

## Documentation

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

### Template

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

### Result

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

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