I have a code below which setups cookie and then adds this cookie to the response with set_cookies
function. However, even though I return a response I received the following error:
ValueError: View function did not return a response
My code is simply this:
def login():
if request.method == "POST":
timestamp = str(int(time.time()))
cookie = timestamp+'user'
cookie = base64.b64encode(cookie.encode('utf-8')).decode('utf-8')
resp = make_response()
resp = resp.set_cookie("LoginCookie",cookie)
return resp
response.set_cookie is an in-place operation. This means that if you set something to it's return value, it will be None, which is the default return value (functions with no return return None). What should be used instead is:
resp.set_cookie("LoginCookie",cookie)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.