render_markup filter, specify the markup filter as a string

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from django import template

register = template.Library()

@register.filter
def render_markup(string, markup_lang=None):
    from django.contrib.markup.templatetags import markup
    if markup_lang:
        markup_lang = markup_lang.lower()
        try:
            return getattr(markup, markup_lang)(string)
        except AttributeError:
            raise ValueError("Markup filter %r not found." % markup_lang)
    return string

More like this

  1. Analogue template filter to removetags that also removes the content of the tag by piquadrat 3 years, 5 months ago
  2. Form row filter by kylefox 6 years, 2 months ago
  3. filter for extracting a number of paragraphs from any HTML code by rafadev 2 years, 10 months ago
  4. i18n base model for translatable content by foxbunny 5 years, 9 months ago
  5. View decorator to automate templates. by jafo 4 years, 2 months ago

Comments

(Forgotten your password?)