我正在开发一个 django 项目,并且我将在多个 View 中显示几个模态,因此我正在考虑创建一个名为 template_tags.py
的文件,而不是:
<div class='modal fade' id='myModal'>
...
</div>
在 View 上,我在 template_tags.py
上创建模式,然后使用
{{myModal}}
从服务器角度来说这是一个坏主意吗?
最佳答案
不,这不是一个坏主意。但是there has to be a better way !
为什么不在 HTML 文件中编写模式,例如 my_modal.html
然后只是 include
在其他模板中,如下所示:
<!-- another_template.html -->
{% include 'path/to/my_modal.html' %}
如果您想在 my_modal.html
内传递参数,请这样做:
<!-- another_template.html -->
{% include 'path/to/my_modal.html' with var1='abc' var2='cba' %}
关于python - Django 中的模板标签过多是否不好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42840651/