我正在使用flask为我的网站编程登录页面,以下是页面脚本:
@app.route("/login/", methods = ["POST", "GET"])
def log_in():
if request.method == "POST":
attempted_username = request.form.get('username')
attempted_password = request.form.get('password')
if attempted_username == 'username':
if attempted_password == 'password':
return render_template('logged_in.html')
else:
return render_template('log_in.html')
进入页面没有问题,但是一旦我提交任何内容,不管它是有效的还是无效的,我都会得到以下错误:
ValueError: View function did not return a response
我知道错误,这意味着这个函数没有返回任何浏览器可以显示的内容,但我不知道漏洞在哪里。我甚至试图在每个if
语句之后加上else
语句,但也没用。我试着尽我所能做出回应。在
为什么这个函数没有返回任何响应,或者为什么显示错误?在
更新:
我刚刚运行了__init__.py
文件,其中函数是手动设置的(通常通过apache服务器自动执行),他向我展示了:
RuntimeError: The session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.
在您的代码中,
POST
内还有许多if,所以只需删除最后一个else
相关问题 更多 >
编程相关推荐