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. Link filter by sean2000 5 years, 5 months ago
  2. Simple template tag to do |stringformat filter with format from a variable by leopd 2 years, 1 month ago
  3. Functional Filters by waterson 5 years, 7 months ago
  4. Url filter middleware by limodou 6 years, 2 months ago
  5. Export Models by brunobord 4 years, 10 months ago

Comments

(Forgotten your password?)