29π
Yo. π
The answer depends on how much your templates have in common.
-
If your templates do have much in common, i.e. they are pages of some section of your site, or just have a very common structure, then your way of doing it would be correct. I just think that you should use more descriptive names for the blocks.
{% extends base.html %} {% block page_heading %}{% endblock %} ... snazzy code here that shows all the posts by all the users ... {% block extra_content %}{% endblock %}
-
If your templates donβt have much in common, but share some specific block of content, then itβs a different situation since itβs difficult to make a properly inherited structure. You should use the {% include %} tag in this case. For example, make another template that shows posts, say
_list_posts.html
, then use it in the children templates.{% extends base.html %} {% block main %} <h1>Welcome to your posts hangout!</h1> {% include '_list_posts.html' %} {% endblock %}
You could also use the inclusion tag for that.
So, which option should you choose? Try to answer the question: should these two templates have a common parent? If yes, go for the first option. Otherwise, go for the second option.