Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSandro Costa
13,163 PointsIs there any performance impact in using custom template tags vs a database query passed into the view?
Even though I know DRY is super important nowadays, I'm still trying to understand if custom template tags have any performance impact when rendering the template.
Based on your experience, what do you think?
1 Answer
Kenneth Love
Treehouse Guest TeacherThey can, yes. Consider having a template tag that causes a large database query that isn't cached and doesn't use handy features like prefetch_related
or select_related
. Maybe it hits a table without any good indexes, too. Worst case scenario kind of thing.
Sticking that tag onto a page, or multiple pages, is going to cause those pages to be really slow. Of course, you'd have the same slowdown doing that query in the view. BUT if your query only really needed to be on, say, two pages, but you used the template tag on 10 pages...