使用Node Boostrap 4 Form和Python 3 flask进行GET和POST

时间:2019-05-06 15:08:03

标签: python node.js flask npm bootstrap-4

我在html文件中有一个这样的表单,我需要将此表单传递给python文件,它将执行很多工作并将输出返回到html页面。令人困惑的是,我使用npm start来启动网站,并且通常会使用其他烧瓶服务器来进行烧瓶操作。我将如何进行这项工作?我什至需要一台烧瓶服务器?

从python返回的数据应该回到相同的HTML元素或另一个元素。

HTML:

<form action="path/my_script.py" method="post" role="form">
    <div class="form-group">
        <label for="python_input">python input or link</label>
        <input type="text" class="form-control" id="python_input" aria-describedby="pythonHelp" placeholder="Enter python_input required>
            <div class="valid-feedback">Looks good!
            </div>
                 <small id="pythonHelp" class="form-text text-muted">Pick your diamond from James Allen's
                       <a href="https://www.example.com/">website</a> and copy paste the info or URL here</small>
     </div>
</form>

Python 3:

import json
import pandas as pd
from flask import Flask, render_template, request, redirect
import os

app = Flask(__name__)


@app.route('/myForm.html', methods=['POST', 'GET'])
def regression():
    python_input= request.form['python_input']
    #do more stuff here
    return 'you posted the '+str(python_input)


if __name__ == '__main__':
    app.run(port=12345, debug=True)```

0 个答案:

没有答案