且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将数据从HTML表单发送到Flask中的Python脚本

更新时间:2023-11-27 14:16:40

The form tag needs two attributes set:

  1. action: The URL that the form data is sent to on submit. Generate it with url_for. It can be omitted if the same URL handles showing the form and processing the data.
  2. method: Whether to submit the data as a query string (GET) or form data (POST).

Add a view to handle the form data:

@app.route('/handle_data', methods=['POST'])
def handle_data():
    projectpath = request.form['projectFilepath']
    # your code
    # return a response

Set the form's action to that view's URL:

<form action="{{ url_for('handle_data') }}" method="post">
    <input type="text" name="projectFilepath">
    <input type="submit">
</form>

相关阅读

推荐文章