Django template span relationships?
In django, https://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-开发者_开发问答that-span-relationships, span relationships provide an easy way in django to do a JOIN. Is there a way in the template to do this (using template tags)?
You could do that, I think, because when you write a custom template tag you can import models and run queries on them just as you can anywhere else. But it violates the separation of business logic and presentation that Django's model-view-controller (or model-view-template) design works hard to preserve. Why not do your query in a view and pass the results to a template via the template's context?
If you are asking whether Django comes with a pre-built way to do this, the answer is no. The people who created Django want you to run queries in your views.
精彩评论