1👍
✅
I suggest putting your counter in request
. Something like this.
# This code wasn't checked
@register.inclusion_tag('tagtemplate.html', takes_context=True)
def my_tag(context):
request = context.get('request')
counter = getattr(request, 'tag_counter', 0)
request.tag_counter = counter + 1
context['request'] = request
return context
Source:stackexchange.com