Reputation: 1172
Bit of a noob with Flask, sorry.
My application is collecting the value from a drop down then POSTing that string to my flask function. I can (sort of) get at the data by using:
@app.route("/lookupmember", methods=["POST"])
def lookupmember():
member = request.data
print(member)
return member
Interestingly though when I print the value of "member" out there in the python function I see something like:
127.0.0.1 - - [19/Oct/2018 18:15:31] "POST /lookupmember HTTP/1.1" 200 -
b'john doe'
Whats the b'
before the name 'john doe'
?
When I console.log the same value after passing it back in the Ajax caller only the name is printed in the browser console.
I reckon the b' part might be a key or identifier applied by flask? If so, it seems reasonable that there would be a way to use that to parse to get to just the name?
Upvotes: 4
Views: 13811
Reputation: 18105
If member
is of type bytes
, then you should convert it to a string using the decode()
function. Then convert that result to JSON so that you can read it in your browser using the jsonify
function:
@app.route("/lookupmember", methods=["POST"])
def lookupmember():
member = request.data
print(member)
return jsonify(member.decode("utf-8"))
Upvotes: 3