I'm trying to get the post data in flask
@app.route('/getpersonbyid', methods = ['POST'])
personId = (int)(request.form['personId'])
You want to return your
personId value; printing it to the console won't help in a web application:
@app.route('/getpersonbyid', methods = ['POST']) def getPersonById(): personId = int(request.form['personId']) return str(personId) # back to a string to produce a proper response
The parenthesis around
int are meaningless noise, btw, they are not needed in Python and are in this case ignored by the parser.
I'm assuming you are doing something meaningful with the
personId value in the view; otherwise using
int() on the value is a little pointless.
You can also use the
MultiDict.get() method to have the value converted for you:
personId = request.form.get('personId', type=int)
personId will be set to an integer, or
None if the field is not present in the form or cannot be converted to an integer.