【问题标题】:include bootstrap modal template with template tags包含带有模板标签的引导模式模板
【发布时间】:2016-05-27 00:09:45
【问题描述】:

我正在尝试创建一个可包含在我的 html 文件中的引导模式,因为我将表单置于模式中并且我不想每次都创建新的 mdoal。

除了尝试包含表单外,它工作正常。这当然是重要的部分。如何在模板标签中包含模板上下文变量?

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 文件中:

 {% 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}} 是问题所在。有没有办法解决这个问题? 模态渲染很好,打开关闭等我只是无法在表单中传递

【问题讨论】:

    标签: django twitter-bootstrap django-forms django-templates


    【解决方案1】:

    你已经接近了!唯一缺少的是您不需要花括号将其包含在包含标记中

    {% 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 %}
    

    【讨论】:

    • 好作品完美!不敢相信我错过了在发布之前应该多一点耐心。能接受就接受
    • @Slayer - 不用担心,这适用于您尝试在其中使用另一个标签的任何其他 django 标签
    猜你喜欢
    • 2021-05-24
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 2010-12-02
    • 2017-01-05
    • 2013-10-17
    • 2012-12-02
    相关资源
    最近更新 更多