If you have template code that is identical, you can use include tag :
{% include "foo/bar.html" %}
And the included code can be changed using variables:
{% include "name_snippet.html" with person="Jane" %}
Even if the code is different for each template (I think your example is talking about forms with different fields, not sure), you can still use include - just do two blocks:
{% include "startform.html with some_action="post" %} {{ field.errors }} {{ field.label_tag }}: {{ field }} {{ field.field2_tag }}: {{ field2 }} {% include "endform.html %}
There is also template inheritance where you can define a base template and inherit all other templates. Block-based inheritance, you can redefine blocks in the parent template with the new code in the child template. It works very well.
source share