我在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)```