我正在开发一个django项目,并且我会在几个视图中显示几个模态,所以我想创建一个名为template_tags.py
的文件,所以改为的:
<div class='modal fade' id='myModal'>
...
</div>
在视图上,我在template_tags.py
上创建模态,然后使用
{{myModal}}
这是服务器方面的坏主意吗?
答案 0 :(得分:1)
不,这不是一个坏主意。但是there has to be a better way!
为什么不在HTML文件中编写模态,比如说<!-- another_template.html -->
{% include 'path/to/my_modal.html' %}
,然后只需include
就可以在其他模板中编写:
my_modal.html
如果您想在<!-- another_template.html -->
{% include 'path/to/my_modal.html' with var1='abc' var2='cba' %}
内传递参数,请执行以下操作:
var options = {
name: 'preset',
positions: undefined, // map of (node id) => (position obj); or function(node){ return somPos; }
zoom: undefined, // the zoom level to set (prob want fit = false if set)
pan: undefined, // the pan level to set (prob want fit = false if set)
fit: true, // whether to fit to viewport
padding: 30, // padding on fit
animate: false, // whether to transition the node positions
animationDuration: 500, // duration of animation in ms if enabled
animationEasing: undefined, // easing of animation if enabled
ready: undefined, // callback on layoutready
stop: undefined // callback on layoutstop
};