Django: construct value of {% include %} tag dynamically?

后端 未结 3 1045
傲寒
傲寒 2021-02-18 13:37

I\'d like to use an {% include page.html %} tag in my Django template, and construct the value of page.html dynamically.

Is there any way to do

3条回答
  •  悲&欢浪女
    2021-02-18 13:55

    I think that goliney provided a better answer here

    In summary:

    You can combine django's built-in 'with' template tag to assign a dynamically constructed template name to a variable and the 'add' filter and to dynamically construct a template name.

    For example:

     {% with template_name='page_'|add:mode|add:".html" %}
         {% include ""|add:template_name %}
     {% endwith %}
    

提交回复
热议问题