Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么';t函数返回响应,即使I';我肯定是吗?(烧瓶)_Python_Flask - Fatal编程技术网

Python 为什么';t函数返回响应,即使I';我肯定是吗?(烧瓶)

Python 为什么';t函数返回响应,即使I';我肯定是吗?(烧瓶),python,flask,Python,Flask,我正在使用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')

我正在使用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函数未返回响应

我知道这个错误,这意味着函数没有返回浏览器可以显示的任何内容,但我不知道孔在哪里。我甚至试着在每个
if
语句之后放一个
else
语句,这也不起作用。我试着把答案放在任何我能找到的地方

为什么此函数不返回任何响应,或者为什么显示错误

更新:

我刚刚运行了
\uuuuu init\uuuuuu.py
文件,函数手动位于该文件中(通常通过apache服务器自动运行),他向我展示了:

RuntimeError:由于未设置密钥,会话不可用。将应用程序上的密钥设置为唯一和机密的内容


在您的代码中,在
POST
many else if中,只需删除最后一个
else

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')
# <--- end remove else
return render_template('log_in.html')
if request.method==“POST”:
已尝试\u username=request.form.get('username'))
已尝试\u password=request.form.get('password'))
如果尝试\u username==“username”:
如果尝试\u password==“password”:
返回呈现模板('logged\u in.html')

#谢谢您的努力,但它仍然不起作用。@MisterMM23我编辑答案,将
form['username']
替换为
form。获取
方法,尝试它仍然不起作用新错误?我在我的本地机器上测试了这段代码,它工作正常,仍然是相同的错误,但是如果它对您有效,我假设它与其他函数或脚本有关。