开发者

Django--Performance hit in using Template Tags vs. Context variables

开发者 https://www.devze.com 2023-03-13 04:14 出处:网络
I\'m a bit naive as far as Django template processing goes. As far as I understand, template tags are just functions.

I'm a bit naive as far as Django template processing goes. As far as I understand, template tags are just functions.

So, is there any difference in performance in filtering query sets in template tags

开发者_运维问答
   ie. user.profile_set.all.0.followers 

versus filtering queries in the same manner via my View?


The template must be parsed, and at each . it must guess which type of access the next identifier should be. Over the long run, avoiding all this can speed the project up a very tiny bit.


In and of itself there should be no discernible difference since most of the cost of doing this is in the DB access. However, if the template that contains the template tag that does the DB interaction is being included, possibly more than once on a page, then there could be a very noticeable difference.

0

精彩评论

暂无评论...
验证码 换一张
取 消