class Params template Node def __init__ self varname self varname varn

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
class Params(template.Node):
def __init__(self, varname):
self.varname = varname
def render(self, context):
context[self.varname] = '?' + context['request'].GET.urlencode()
return ''
def get_params(parser, token):
"""
Usage: {% get_params as params %}
"""
bits = token.contents.split()
if len(bits) != 3:
raise template.TemplateSyntaxError("'%s' tag takes exactly three arguments" % bits[0])
if bits[1] != 'as':
raise template.TemplateSyntaxError("second argument to '%s' tag must be 'as'" % bits[0])
return Params(bits[2])
register.tag('get_params', get_params)