fancy_tag 0.2.0

A powerful replacement for Django's simple_tag decorator that adds supports for positional, keyword arguments and template variable assignment.


fancy_tag is a template tag decorator designed to replace Django's built in simple_tag decorator. It's backwards compatible with simple_tag and adds new calling options like named arguments.


  • Keyword arguments - arguments can be explicitly assigned to parameter specific parameters in the template tag function
  • Variable length arguments - The "*args" and "**kwargs" notation
  • The trailing "as <varname>" to assign the output of the template tag to a variable in the template's context.


  1. Add the fancy_tag package to your Python path

  2. Instead of:

    def some_tag(arg1, arg2):
        return '%s %s' % (arg1, arg2)


    def some_tag(arg1, arg2):
        return '%s %s' % (arg1, arg2)


Keyword Arguments

Python Code:

def say_cheese(name, thing_to_say='cheese'):
    return 'Hey, %s! Say %s!' % (name, thing_to_say)

Template Code:

{% say_cheese "Jacob" %} -> "Hey, Jacob! Say Cheese!"
{% say_cheese "Malcolm" thing_to_say="Vegemite" %} -> "Hey Malcolm! Say Vegemite!"

Variable Length Arguments

Python Code:

def greet_people(*args):
    return 'Hello, %s' % ', '.join(args)

Template Code:

{% greet_people "Larry" "Darryl" "Darryl" %}


Hello, Larry, Darryl, Darryl

Variable Length Keyword Arguments

Python Code:

def watch_your_mouth(s, **kwargs):
    for key, value in kwargs.items():
        s = s.replace(key, value)
    return s

Template Code:

{% watch_your_mouth "You damn dirty ape!" "damn"="doggone" "dirty"="handsome" %}


You doggone handsome ape!"

Assigning Output To A Variable

Python Code:

def now(format_string):
    df = DateFormat(
    return df.format(format_string)

Template Code:

{% now as just_now %}
Oh no, it's already {{ just_now }}!


Oh no, it's already February 20th, 2010!

Accessing the Template Context

Python Code:

@fancy_tag(register, takes_context)
def say_hello_to_user(context, phrase):
    return u'%s, %s!' % (phrase, context['user'])

Template Context:

{'user': 'Tobias'}  # Provided by a template context processor, for example

Template Code:

{% say_hello_to_user "Hallo" %}


Hallo, Tobias!


With Django in your python path, run tests/ or use tox to run the tests using multiple Python and Django versions.


fancy_tag is Copyright (c) 2010-2012 Sam Bull, Trapeze. It is free software, and may be redistributed under the terms specified in the LICENSE file.


fancy_tag is maintained by Sam Bull, with support from Trapeze.


Sam Bull




  • Framework :: Django
  • Programming Language :: Python
  • License :: OSI Approved :: BSD License
File Type Python Version Uploaded On Downloads
fancy_tag-0.2.0.tar.gz Source Oct. 29, 2012 32,071
Version Release Date
0.2.0 Oct. 29, 2012
0.1.5 Dec. 13, 2010
0.1.4 Dec. 13, 2010
0.1.2 Aug. 24, 2015
Date Package Version Action
Aug. 24, 2015, 11:13 p.m. fancy_tag 0.2.0 Release Created
Aug. 24, 2015, 11:13 p.m. fancy_tag 0.1.5 Release Created
Aug. 24, 2015, 11:13 p.m. fancy_tag 0.1.4 Release Created
Aug. 24, 2015, 11:13 p.m. fancy_tag 0.1.2 Release Created
Aug. 24, 2015, 11:13 p.m. fancy_tag Package Created