如何在引导模态下使用Python烧瓶和Flash显示预测结果

时间:2019-06-22 05:50:24

标签: python html flask python-requests flask-wtforms

我试图在单击提交按钮时显示从python Flask代码中执行的计算获得的结果。用户输入的输入和提交按钮以一种模式形式显示。单击提交按钮后,我希望输出在同一页面上的另一个引导程序模式中闪烁。 请帮助。 我已附上代码以供参考

我参考了以下链接以寻求帮助,但无法成功- how to show bootstrap modal on rendering the same page in flask

The screenshot is captured when I inspect the HTML page. The result is displayed within the inspect element tab, but not as a modal form when the submit button is clicked.

HTML代码:

<div class="modal-footer">
    <div class = "button-group" data-toggle="modal" data-backdrop="false">  
    <id = submit data-target="#Result">
         <button> {{ form.submit(class="") }} </button>
   </div>
</div>

    <div class="modal" tabindex="-1" role="dialog" id="Result" data-backdrop = "static">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">Result display</h4>
                </div>
                <div class="modal-body">
                    {% for message in get_flashed_messages() %}
                        {{ message }}
                    {% endfor %}
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
           </div>
       </div>
</div>

PYTHON代码:

def display():
    if form.validate_on_submit():
        prediction = predict (a,b,c,d)
        result =  prediction 
        if (result!= None):
            flash(result)
        return redirect(url_for('circular'))
    return render_template("pred.html", form=form)

由于我是使用Python Flask和HTML进行Web开发的新手,请提供帮助。

0 个答案:

没有答案