class BaldDudeImgNode template Node def __init__ self idx self idx idx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
class BaldDudeImgNode(template.Node):
def __init__(self, idx):
self.idx = idx
def render(self, context):
return dir(context)
output = context.render(self.idx)
return context['item'] #eval(self.idx, context, context)
if self.idx == 1: return '<img src="/media/openinfo_23.jpg" width="78" height="103" alt="" />'
elif self.idx == 2: return '<img src="/media/openinfo_20.jpg" width="78" height="103" alt="" />'
return '<img src="/media/openinfo_25.jpg" width="78" height="103" alt="" />'
def do_BaldDudeImg(parser, token):
try:
tag_name, format_string = token.split_contents()
except ValueError:
msg = '%r tag requires a single argument' % token.contents[0]
raise template.TemplateSyntaxError(msg)
return BaldDudeImgNode(format_string)
register.tag('BaldDudeImg', do_BaldDudeImg)
а вызываю как {% BaldDudeImg item.dude-img %}