You can access the MEDIA_URL
in flat pages via a templatetag. Look at this snippet
It searches for {{ MEDIA_URL }}
and replaces it with that found in your settings.
from django import template
from django.conf import settings
from django.template.defaultfilters import stringfilter
register = template.Library()
@register.filter
@stringfilter
def media_url(value):
"""Searches for {{ MEDIA_URL }} and replaces it with the MEDIA_URL from settings.py"""
return value.replace('{{ MEDIA_URL }}', settings.MEDIA_URL)
media_url.is_safe = True
And the usage:
{% load media_url %}
{{ flatpage.content|media_url }}
To set up, drop the above code into a file called media_url.py
in your templatetags
directory in one of your INSTALLED_APPS
, and add the filter to your flatpages template like so