SoFunction
Updated on 2024-11-13

A summary of the three ways flask post gets front-end request parameters

flask post get front-end request parameters way

There are three ways to post request python flask to get the parameters sent from the frontend

1, put inside params

from flask import request
# params take request
data = {}
for key in :
    data[key] = (key)
 
file_type = data['file_type']
safety_check_command = data['safety_check_command']
remark = data['remark']
create_user = data['create_user']
weight = data['weight']

2. form-data with attachments

Note: Without attachments, the front-end server express+pm2 may have problems.

from flask import request
 
file_obj = ('excel')
DeploymentID = ['DeploymentID']  # Get DeploymentID
environment = ['environment']  # Getting the environment
project = ['project']  # Get the project

3、json format

from flask import request, json
 
data = request.get_data()
json_data = (("UTF-8"))
 
DeploymentID = json_data.get("DeploymentID")
Gitlab_URL = json_data.get("Gitlab_URL")
basics_URL = json_data.get("basics_URL")

summarize

The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.