包含带有模板标签的引导模态模板 [英] include bootstrap modal template with template tags
问题描述
我正在尝试创建一个可以包含在我的html文件中的引导程序模态,因为我将表单置于模态中并且我不想每次都创建一个新的mdoal。
I'm trying to create a bootstrap modal that can be included in my html files since I'm putting forms in modal and I don't want to create a new mdoal everytime.
它可以正常工作,除了尝试包含表格。这当然是重要的部分。如何在模板标记中包含模板上下文变量?
It works fine, except for trying to include the form. Which is of course the important part. How could I include a template context variable inside a template tag?
modal_base
modal_base
{% load crispy_forms_tags %}
<div id="{{ modal_form_id }}" class="modal fade" ariahidden="True">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<a class="close" data-dismiss="modal">X</a>
<h1 style="text-align:center;">
{{ modal_form_title }}
</h1>
</div>
<div class="modal-body">
<form method="{{modal_form_method|default:'POST'}}" action="{{modal_form_action}}">
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="Create"/>
</form>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-danger" data-dismiss="modal">
Cancel
</a>
</div>
</div>
</div>
</div>
示例包含在某些html文件中:
Example include in some html file:
{% include 'modal_form.html' with modal_form_id="new-category" modal_form_title="Create a New Category" modal_form_method="POST" modal_form_action="/home/" form={{category_form}} %}
form = {{category_form}}是问题所在。有办法解决这个问题吗?
模态可以很好地显示,打开,关闭等,我无法以这种形式传递
form = {{category_form}} is the issue. Is there a way to get around this? The modal renders fine, opens closes etc I just can't pass in the form
推荐答案
您已关闭!唯一缺少的是您不需要花括号将其包含在include标记内
You're close! the only thing missing is that you don't need the curly braces to include it within the include tag
{% include 'modal_form.html' with modal_form_id="new-category" modal_form_title="Create a New Category" modal_form_method="POST" modal_form_action="/home/" form=category_form %}
这篇关于包含带有模板标签的引导模态模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!