@register.tag
def get_upcoming_events(parser, token):
 try:
  (tag_name, arg) = token.contents.split(None, 1)
 except ValueError:
  raise template.TemplateSyntaxError, ('%r tag requires arguments' % token.contents.split()[0])
 matches = re.search('([0-9]+) as (\\w+)', arg)
 if (not matches):
  raise template.TemplateSyntaxError, ('%r tag had invalid arguments' % tag_name)
 (limit, var_name) = matches.groups()
 return UpcomingEventsNode(var_name, limit)

@ register . tag def get_upcoming_events ( parser , token ) : try : ( tag_name , arg ) = token . contents . split ( None , 1 ) except ValueError : raise template . TemplateSyntaxError , ( '%r tag requires arguments' % token . contents . split ( ) [ 0 ] ) matches = re . search ( '([0-9]+) as (\\w+)' , arg ) if ( not matches ) : raise template . TemplateSyntaxError , ( '%r tag had invalid arguments' % tag_name ) ( limit , var_name ) = matches . groups ( ) return UpcomingEventsNode ( var_name , limit )
returns a node which alters the context to provide upcoming events the upcoming events are stored in the variable specified .