Can a cookie be set when using jsonify?
jsonify
returns a Response
object, so capture it before returning from your view and add the cookie then with Response.set_cookie
.
out = jsonify(state=0, msg='success')out.set_cookie('my_key', 'my_value')return out
You might want to just add the value to the session cookie. Flask's session
will json encode values and sign the cookie for security, something you have to manually do when using set_cookie
.
from flask import sessionsession['my_key'] = 'my_value'