Django Template inheritance: how many levels and what page to render

前端 未结 2 614
孤城傲影
孤城傲影 2021-01-04 17:42

I would like to have some advice in constructing django template levels.

Reading the docs, I do not understand how to create a template hierarchy structure with more

2条回答
  •  时光说笑
    2021-01-04 18:09

    Probably not the best way of doing it but you might user include https://docs.djangoproject.com/en/dev/ref/templates/builtins/#include

    something like this for base_level2.html

    {% extends "base.html" %}
    {% block level2 %}
    Second level
    {% include "level2_level3_1.html" %}   
    {% include "level2_level3_2.html" %} 
    {% endblock %}
    

    i've not tested this, so not sure it works.

    and btw:

    The include tag should be considered as an implementation of “render this subtemplate and include the HTML”, not as “parse this subtemplate and include its contents as if it were part of the parent”. This means that there is no shared state between included templates – each include is a completely independent rendering process.

提交回复
热议问题