@register.tag(name=u'user_display')
def do_user_display(parser, token):
 bits = token.split_contents()
 if (len(bits) == 2):
  user = bits[1]
  as_var = None
 elif (len(bits) == 4):
  user = bits[1]
  as_var = bits[3]
 else:
  raise template.TemplateSyntaxError(u"'{0}' takes either two or four arguments".format(bits[0]))
 return UserDisplayNode(user, as_var)

@ register . tag ( name = u'user_display' ) def do_user_display ( parser , token ) : bits = token . split_contents ( ) if ( len ( bits ) == 2 ) : user = bits [ 1 ] as_var = None elif ( len ( bits ) == 4 ) : user = bits [ 1 ] as_var = bits [ 3 ] else : raise template . TemplateSyntaxError ( u"'{0}' takes either two or four arguments" . format ( bits [ 0 ] ) ) return UserDisplayNode ( user , as_var )
example usage:: {% user_display user %} or if you need to use in a {% blocktrans %}:: {% user_display user as user_display} {% blocktrans %}{{ user_display }} has sent you a gift .