simple string formatting filter

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

register = template.Library()

def format(value, arg):
    """
    Alters default filter "stringformat" to not add the % at the front,
    so the variable can be placed anywhere in the string.
    """
    try:
        if value:
            return (unicode(arg)) % value
        else:
            return u''
    except (ValueError, TypeError):
        return u''
register.filter('format', format)

More like this

  1. CallTag - Just like include, but can pass parameters to it by limodou 5 years, 2 months ago
  2. Url filter middleware by limodou 5 years, 2 months ago
  3. filter for extracting a number of paragraphs from any HTML code by rafadev 11 months, 2 weeks ago
  4. nofollow filter for external links by muhuk 3 years, 1 month ago
  5. A RegexpField that clean the regex match using the desired format by nasp 1 year, 8 months ago

Comments

(Forgotten your password?)