mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Fixed #19890 -- ifchanged templatetag rendered its content twice
The content of ifchanged template tag was rendered twice: first time, to compare it with the previous value and the second time, to return the rendered output.
This commit is contained in:
		| @@ -223,6 +223,7 @@ class IfChangedNode(Node): | ||||
|         if self not in state_frame: | ||||
|             state_frame[self] = None | ||||
|  | ||||
|         nodelist_true_output = None | ||||
|         try: | ||||
|             if self._varlist: | ||||
|                 # Consider multiple parameters.  This automatically behaves | ||||
| @@ -230,13 +231,13 @@ class IfChangedNode(Node): | ||||
|                 compare_to = [var.resolve(context, True) for var in self._varlist] | ||||
|             else: | ||||
|                 # The "{% ifchanged %}" syntax (without any variables) compares the rendered output. | ||||
|                 compare_to = self.nodelist_true.render(context) | ||||
|                 compare_to = nodelist_true_output = self.nodelist_true.render(context) | ||||
|         except VariableDoesNotExist: | ||||
|             compare_to = None | ||||
|  | ||||
|         if compare_to != state_frame[self]: | ||||
|             state_frame[self] = compare_to | ||||
|             return self.nodelist_true.render(context) | ||||
|             return nodelist_true_output or self.nodelist_true.render(context)  # render true block if not already rendered | ||||
|         elif self.nodelist_false: | ||||
|             return self.nodelist_false.render(context) | ||||
|         return '' | ||||
|   | ||||
		Reference in New Issue
	
	Block a user