使用include标记包含调用它的相同模板

时间:2017-10-11 08:31:30

标签: django django-templates

我有一个用例,根据include标记和传递给它的参数,表单的不同字段的呈现方式不同。为了保持DRY,有时候我想要包含相同的模板并将其传递给不同的参数,如下面的简化示例所示:

main_form.html

{% include "./field-snippet.html" with type=list %}

field_snippet.html

{% include "./field-snippet.html" with type="regular" %}

但是这给出了以下TemplateSyntaxError

The relative path '"./field-snippet.html"' was translated to template name 'myappname/field-snippet.html', the same template in which the tag appears.

或者,我可以为不同类型的字段提供不同的html文件,但这似乎是许多文件,每个文件的代码都不多。关于如何最好地接近这个的任何想法?在这里使用自定义Widgets是最好的方法(我还没有玩过很多)

0 个答案:

没有答案
相关问题