1👍
✅
I’m not exactly sure what you need to accomplish or if your approach is indeed the best approach, but I’d suggest your look into the forloop.first
variable before you go too far down this road. Your approach seems awkward at best at a glance, but I could be wrong since I don’t know the specifics of the situation
Most likely you should be able to make this work to your needs, however if it falls short I’d suggest that the source for the for
template tag (and it’s forloop
variable) would likely be very illustrative on how you might implement what you’re looking to do.
👤John
1👍
What I ended up doing is saving a variable within the context and checking for that in the Node’s render method:
class CustomNode(template.Node):
def render(self, context: dict) -> str:
context['already_rendered'] = context.get('already_rendered', set())
if self.__class__ in context['already_rendered']:
return ''
context['already_rendered'].add(self.__class__)
...
- [Answered ]-Django ModelForm not displayed in template
- [Answered ]-Django – query for the closest numeric value to a given value
- [Answered ]-Django not redirecting to desired url after login
- [Answered ]-Django Unable to create model-based form: "str object not callable"
- [Answered ]-Django 1.8 Durationfield and time difference
Source:stackexchange.com