繁体   English   中英

为什么我会收到“在服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试”

[英]Why am I getting "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again"

我很确定我的问题出在我的这部分代码中。 如果我将 <form action="/update/{id}" 更改为登录,我可以让所有路由按应有的方式运行,并允许用户输入新密码并将它们发送到登录屏幕。 但我不知道如何让它保存该密码,然后让用户使用新密码登录。

@app.route('/update/<int:id>', methods=['GET', 'POST'])
@login_required
def update(id):
form = UpdatePasswordForm()
userPass = User.query.get(id)
if request.method == "POST":
    userPass.password = request.form['password']


    try:
        db.session.commit()
        flash("User Updated Successfully!")
        return render_template("update.html",
                               form=form,
                               userPass=userPass,
                               id=id)
        redirect(url_for('login'))

    except:
        flash("Error! There was a problem changing your password")
        return render_template("update.html",
                               form=form,
                               userPass=userPass,
                               id=id)
        redirect(url_for('update'))
else:
    return render_template("update.html",
                           form=form,
                           userPass=userPass,
                           id=id)
    redirect(url_for('update'))

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <title>Update Page</title> </head> <body> <h1>Update Password</h1> <form action="/update/{id}" method="POST"> {{ form.password(class="form-control", value=userPass.password) }} {{ form.submit}} </form> </body> </html>

我猜您在 id 变量中缺少一些括号

<form action="/update/{id}" method="POST">

应该改为

<form action="/update/{{id}}" method="POST">

Jinja 需要双花括号来表示变量。 https://jinja.palletsprojects.com/en/3.0.x/templates/#variables

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM