Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 632753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:06:39+00:00 2026-05-13T20:06:39+00:00

In this excellent Google Tech Talk by Jacob Kaplan-Moss, Jacob says that they added

  • 0

In this excellent Google Tech Talk by Jacob Kaplan-Moss, Jacob says that they added support for the include template tag despite previous dogmatic objections, and says that people shouldn’t use it.

Does anyone know why? A quick search didn’t show anything that would explain why. There’s nothing relevant in the now-fixed ticket where support for an include tag was added. I use include tags liberally to avoid repeating myself, which seems like a good idea, but maybe I’m missing some core reason why those who know think it’s bad.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:06:40+00:00Added an answer on May 13, 2026 at 8:06 pm

    I suppose he wants to encourage template reuse by inheritance (using extends) rather than by composition. Perhaps the implication is that if you can’t organise your templates this way, the dogmatic opinion is that your site is organised poorly. (For example, if you are reusing a navigation menu, shouldn’t it always be in the same place in the page structure? Why should each individual page decide where to put it?)

    By the way, using include doesn’t do much to help you stay DRY, because any context that the included template requires must be passed from all the views that use it.

    By contrast, using a custom inclusion template tag allows you to execute arbitrary Python code at the point where the tag is included, rather than in the view (or by shoving it into a model just to make it easier to access in the template).

    As a trivial example, I wanted to show a list of users’ avatars. Using include, it looks like this:

    {% for user in users %}
        {% with user.gravatar_url as avatar_url %}
            {% include "foo/bar/avatar.html" %}
        {% endwith %}
    {% endfor %}
    

    With a custom tag:

    {% for user in users %}
        {% gravatar user.email %}
    {% endfor %}
    

    Using the custom inclusion tag meant that the Gravatar hashing logic no longer had to be a concern of the User model, nor of the view function.


    This said, I think are are some situations where you inevitably have similar data in the context of multiple templates, you don’t need to do anything fancy with it, you just want to display some of its attributes so you don’t want to write a function to make it work.

    For example, I wrote a blog application (who hasn’t?) which had two types of archive view: a basic sequential, X-posts-per-page one, and a monthly archive view. Both templates obviously had a list of posts in their context, both used exactly the same summary template fragment to show a title and excerpt from each post, but each template presented them in a slightly different context. So I used:

    {# in archive_index.html #}
    {% extends "base.html" %}
    
    {# some stuff specific to sequential archives here #}
    
    {% for post in posts %}
        {% include "post_summary.html" %}
    {% endfor %}
    
    {# probably more stuff specific to sequential archives #}
    

    And…

    {# in archive_monthly.html #}
    {% extends "base.html" %}
    
    {# some stuff specific to monthly archives here #}
    
    {% for post in posts %}
        {% include "post_summary.html" %}
    {% endfor %}
    
    {# probably more stuff specific to monthly archives #}
    

    It really seems that in this case, composition makes more sense than inheritance. In fact it was difficult at first to imagine how inheritance would work here at all. Well, it’s still possible:

    {# in base_archive.html #}
    {% extends "base.html" %}
    
    {% block archive_header %}{% endblock %}
    
    {% for post in posts %}
        {% include "post_summary.html" %}
    {% endfor %}
    
    {% block archive_pagination %}{% endblock %}
    

    Now, the two different archives extend this and just inject their unique stuff into the blocks:

    {# in archive_monthly.html #}
    {% extends "base_archive.html" %}
    
    {% block archive_header %}
        <h1>Archive for {{ month }}</h1>
    {% endblock %}
    
    {% block archive_pagination %}
        {# previous/next month links here #}
    {% endblock %}
    

    I’ll leave imagining what archive_index.html looks like as an exercise for the (no doubt bored) reader.

    Phew! It feels smart to have come up with a way of doing the same thing using both composition and inheritance, but is the latter just bending over backwards to conform to the dogma that Jacob Kaplan-Moss mentioned?

    Having just watched the video (yes, all 1 hour 5 minutes of it, just so I could finish answering this question), I don’t think Jacob would be enormously bothered. It sounded like an off-the-cuff comment, maybe a reference to which technique you ought to consider first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I managed to apply this excellent example to my needs: http://code.google.com/p/galleriffic/issues/attachmentText?id=76&aid=-3045121742886940548&name=example-2.html&token=4nlvmgAfVpc5whcXC9UEqHZaSz0%3A1339257750721 With a small
This is in reference to this (excellent) answer . He states that the best
I went through this excellent tutorial of google https://developers.google.com/maps/articles/phpsqlsearch but i din't understand the
Google has an excellent blog that has a fairly neat header - as you
I was reading this excellent article on V8, Google's Javascript engine: https://developers.google.com/v8/design#mach_code . At
In this excellent SO question , differences between CTE and sub-queries were discussed. I
I was reading about this excellent post on metaclasses What is a metaclass in
Reading through this excellent article about safe construction techniques by Brain Goetz, I got
I have been using this excellent decorator for memoization, which I found on the
EDIT: a few weeks after I posted this question Evan Coury wrote an excellent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.