简体   繁体   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"

I'm pretty sure my problem is somewhere in this part of my code.我很确定我的问题出在我的这部分代码中。 If I change <form action="/update/{id}"to login, I can get all the routes running the way they should and allowing the user to enter a new password and send them to the login screen.如果我将 <form action="/update/{id}" 更改为登录,我可以让所有路由按应有的方式运行,并允许用户输入新密码并将它们发送到登录屏幕。 But I can not figure out how to get it to save that password and then let the user login with the new password.但我不知道如何让它保存该密码,然后让用户使用新密码登录。

@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>

I guess you are missing some brackets here in the id variable我猜您在 id 变量中缺少一些括号

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

It should be instead应该改为

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

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

暂无
暂无

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

相关问题 FLASK - 在服务器上找不到请求的 URL。 如果您手动输入 URL 请检查您的拼写并重试 - FLASK - The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again 在服务器上找不到请求的 URL。 如果您手动输入 URL,请检查您的拼写并重试 - The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again python flask URL 错误:&#39;在服务器上找不到请求的 URL。 如果您手动输入了 URL,请检查您的拼写并重试。 - python flask URL error: 'The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.' Flask - 404 未找到:在服务器上未找到请求的 URL。 如果您手动输入 URL,请检查您的拼写并重试 - Flask - 404 Not found : The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again Flask: Not Found 在服务器上找不到请求的 URL。 如果您手动输入了 URL,请检查您的拼写并重试 - Flask: Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again Flask: Not Found 在服务器上找不到请求的 URL。 如果您手动输入 URL,请检查您的拼写并重试 - Flask: Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again Flask 错误:在服务器上找不到请求的 URL。 如果您手动输入 URL 请检查您的拼写并重试 - Flask error: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again 在服务器上找不到请求的 URL。 如果您手动输入了 URL,请检查您的拼写并重试。 404 - The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. 404 Python Flask API:在服务器上找不到请求的 ZE6B391A8D2C4D45902A23A8B6587。 如果您手动输入 URL 请检查您的拼写并重试 - Python Flask API : The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again Flask 应用程序 - 错误 404,在服务器上找不到请求的 URL。 如果您手动输入了 URL,请检查您的拼写并重试 - Flask app - Error 404, The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM