Login

Use MEDIA_URL in flatpages with SSL

Author:
gobble
Posted:
July 2, 2010
Language:
Python
Version:
1.0
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. Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 6 months ago

Comments

Please login first before commenting.