@register.tag
def ifchanged(parser, token):
 bits = token.split_contents()
 nodelist_true = parser.parse(('else', 'endifchanged'))
 token = parser.next_token()
 if (token.contents == 'else'):
  nodelist_false = parser.parse(('endifchanged',))
  parser.delete_first_token()
 else:
  nodelist_false = NodeList()
 values = [parser.compile_filter(bit) for bit in bits[1:]]
 return IfChangedNode(nodelist_true, nodelist_false, *values)

@ register . tag def ifchanged ( parser , token ) : bits = token . split_contents ( ) nodelist_true = parser . parse ( ( 'else' , 'endifchanged' ) ) token = parser . next_token ( ) if ( token . contents == 'else' ) : nodelist_false = parser . parse ( ( 'endifchanged' , ) ) parser . delete_first_token ( ) else : nodelist_false = NodeList ( ) values = [ parser . compile_filter ( bit ) for bit in bits [ 1 : ] ] return IfChangedNode ( nodelist_true , nodelist_false , * values )
checks if a value has changed from the last iteration of a loop .