Login

Use MEDIA_URL in flatpages with SSL

Author:
gobble
Posted:
July 2, 2010
Language:
Python
Version:
1.0
Tags:
filter ssl context flatpages processor
Score:
0 (after 0 ratings)

This is a copy of snippet 654, modified to allow dynamic MEDIA_URL, as you might need that for SSL in combination with snippet 1754.

This is a template filter to enable the use of the MEDIA_URL setting in content from the flatpages database table. It searches for {{ MEDIA_URL }} and replaces it with the current MEDIA_URL added by a context processor.

Note: 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:

{% load media_url %} {{ flatpage.content|media_url:MEDIA_URL }}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from django import template
from django.template.defaultfilters import stringfilter

register = template.Library()

@register.filter
@stringfilter
def media_url(value,MEDIA_URL):
    """Searches for {{ MEDIA_URL }} and replaces it with the current MEDIA_URL"""
    return value.replace('{{ MEDIA_URL }}', MEDIA_URL)
media_url.is_safe = True

More like this

  1. Use MEDIA_URL in flatpages by robhudson 7 years, 4 months ago
  2. Load static media from secure (SSL) static server (Context Processor) by ianreardon 5 years, 9 months ago
  3. Use MEDIA_URL in 500 error page by bthomas 6 years, 8 months ago
  4. Dynamic Django settings context processor by sciyoshi 7 years ago
  5. Cycling MEDIA_URL context processor by girasquid 6 years, 8 months ago

Comments

Please login first before commenting.