Jinja 中包含 html 的按钮?

Buttons that include html with Jinja?

我正在使用 Python 和 Flask 构建一个应用程序。我有一个带有两个选项的下拉按钮。我想要它让这两个选项 include 在某个 div 中有不同的 html。有没有办法用 Jinja 做到这一点?我对网络开发还很陌生。

这是我得到的(不起作用)但显示了我正在尝试做的事情。

 <div class="btn-group" role="group">
        <!-- Split button -->
                <div class="btn-group">
                  <button type="button" class="btn btn-default">Topic Modle</button>
                  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <span class="caret"></span>
                    <span class="sr-only">Toggle Dropdown</span>
                  </button>
                  <ul class="dropdown-menu">

                    <li><a href="#lsa">LSA</a></li> <!-- I want this button to include vis_lsa.html -->

                    <li><a href="#lda">LDA</a></li> <!-- and this button to include vis_lda.html -->

                  </ul>
                </div>

        {% if #lsa %}
         {% include 'vis_lsa.html' %}
        {% endif %}

        {% if #lda %}
         {% include 'vis_lda.html' %}
        {% endif %}

    </div>

我查看了模板的 Jinja 文档,但没有找到与我正在尝试做的类似的内容。我不确定我是否需要 jQuery 来代替?我不知道任何 jQuery,所以希望我不需要它来做这件事。

您可以在下拉列表中使用包含 type="submit" 的表单标签,然后显式创建一个 custom filter that checks if the request.form value is either lsa or lda after which it includes the appropriate html file. The request variable is available 到 Jinja。