简体   繁体   English

查看功能未在烧瓶中返回响应

[英]View function did not return a response in flask

I have a code below which setups cookie and then adds this cookie to the response with set_cookies function. 我在下面有一个代码设置cookie,然后使用set_cookies函数将此cookie添加到响应中。 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. response.set_cookie是一个就地操作。 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). 这意味着如果你设置了它的返回值,它将是None,这是默认的返回值(没有返回的函数返回None)。 What should be used instead is: 应该使用的是:

resp.set_cookie("LoginCookie",cookie)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flask 视图返回错误“视图函数未返回响应” - Flask view return error "View function did not return a response" Flask REST API错误:视图函数未返回有效响应 - Flask REST API Error: The view function did not return a valid response Flask返回TypeError:视图函数未返回有效响应 - Flask is returning TypeError: The view function did not return a valid response FLASK-python ValueError:视图函数未返回响应 - FLASK-python ValueError: View function did not return a response 查看功能未返回响应 - View function did not return a response Flask应用程序中的“视图功能未返回有效响应。”错误在哪里? - Where is the “The view function did not return a valid response.” error in my Flask app? 错误在哪里?“视图函数未返回有效响应。 ”在我的烧瓶应用程序中? - Where is the error “The view function did not return a valid response. ” in my flask app? 如何解决TypeError: The view function did not return a valid response in python flask api - How to solve the TypeError: The view function did not return a valid response in python flask api 写入json文件时,烧瓶“ ValueError:视图函数未返回响应” - flask “ValueError: View function did not return a response” when write to json file Flask TypeError:“**”的视图 function 未返回有效响应。 function 要么返回 None 要么在没有返回语句的情况下结束 - Flask TypeError: The view function for '**' did not return a valid response. The function either returned None or ended without a return statement
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM