python - Django 中的模板标签过多是否不好?

标签 python html django

我正在开发一个 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/

相关文章:

python - Django 中的动态字段计算

django - 在 Django Admin 中自定义日期选择器

html - 父有序列表中的嵌套无序列表

javascript - AngularJS 无法访问 Controller 内的指令范围

javascript - 如何在悬停另一个 HTML 元素时创建平滑缩放并显示叠加层?

Django、PayPal IPN 和用户名——概念问题

python - 如何设置 Selenium 以使用多个 Firefox 配置文件?

python - 在wxPython中,event.Skip()和event.Veto()有什么区别?

python - 如何扩展多边形直到其中一个边界到达一个点

python - Django Rest Framework RelatedField 无法返回字典对象