[Answered ]-Django Templates Variable Resolution

2👍

It’s not really a question of variable resolution. The issue is how you’re getting the terms from the Post object.

When, inside your template tag, you do for term in terms.all(), the all is telling Django to re-evaluate the queryset, which means querying the database again. So, your carefully-annotated terms are getting refreshed with new objects from the database, and the permalink attribute is getting overridden.

It will probably work if you just drop the all – so you just have for term in terms:. This will re-use the existing objects.

Leave a comment