werkzeug.routing.BuildError: Could not build url for endpoint 'forgot_passwd' with values ['token']. Did you mean 'logout' instead?

werkzeug.routing.BuildError: Could not build url for endpoint 'forgot_passwd' with values ['token']. Did you mean 'logout' instead?

@app.route("/forgotpasswd",methods=["GET","POST"])
def parola_unuttum():
    form = forgotpasswd(request.form)
    sifre_adresi = form.sifre_mail.data
    if request.method == "POST" and form.validate():
        

        cursor=Mysql.connection.cursor()
        sorgu = "SELECT email from users where  email = %s"
        result = cursor.execute(sorgu,(sifre_adresi,))
        
        if result >= 1:
            token = secret.dumps(sifre_adresi, salt='forgotpasswd')
            msg = Message('Şifre değiştirme', sender='xxxxx@gmail.com', recipients=[sifre_adresi])
            link = url_for('forgot_passwd', token=token, _external=True)

            msg.body = 'Şifre değiştirme linkiniz budur ------>  {}'.format(link)
            mail.send(msg)
            flash("Birkaç dakika sonra mail ulaşacaktır.","info")
            return redirect(url_for("login"))
        else:
            flash("Mail not found! lütfen geçerli bir adres giriniz.","info")
            return render_template("forgotpasswd.html",form=form)
        return render_template("forgotpasswd.html",form=form)

令牌代码;

@app.route('/forgot_passwd/<token>',methods=['GET', 'POST'])
#@limiter.limit("1/second",error_message='Lütfen Spam Yapmayın!!')
def sifremiunuttum(token):
    form = Newpasswd(request.form)
    password=form.passwd.data
    if request.method == "POST" and form.validate():
        try:
            email = secret.loads(token, salt='forgotpasswd', max_age=3600)
        except SignatureExpired:
            flash("Zaman aşımı lütfen yeniden  mail isteyiniz!","danger")
            return render_template("index.html")
        finally:
            cursor=Mysql.connection.cursor()
            sorgu = "UPDATE users set password='{}' WHERE email= '{}' ".format(password,email)
            cursor.execute(sorgu)
            Mysql.connection.commit()
            cursor.close()
            flash("Parola değiştirildi","success")
            return redirect(url_for("login"))
    return render_template("yeniparola.html",form=form)

HTML 文件;

{% extends "layout.html" %}
{% block body %}
{% from "includes/formhelpers.html" import render_field %}

<form method="POST" >
    <dl>
        {{ render_field(form.sifre_mail,class="form-control") }}
        {{form.recaptcha}}
        {% for  error in form.recaptcha.errors %}
        <ul>
            <li style="color:red;"> Recaptcha Doğrulayın!</li>
        {% endfor %}
        </ul>
    </dl>
    <button type="submit" class="btn btn-secondary btn-sm">Reset</button>
    
    </form>


{% endblock body %}

当我说发送邮件时,我收到此错误
错误werkzeug.routing.BuildError:无法为端点'forgot_passwd'构建url,值为['token'] .你的意思是'logout'吗?
我看了html页,好像没有问题。没看懂问题出在哪里。

flask 已经有一个强大的内置 cli 命令到 dump 您的应用程序的所有可用路由

尝试 flask --help 探索 flask 的所有可用命令,可能还有其他已安装的扩展(例如:flask-migratedb)。

尝试 flask routes --help 获得 help 关于 flask routes 命令:

(venv) C:\myapps\flask\helloflask>flask routes --help
Usage: flask routes [OPTIONS]

  Show all registered routes with endpoints and methods.

Options:
  -s, --sort [endpoint|methods|rule|match]
                                  Method to sort routes by. "match" is the
                                  order that Flask will match routes when
                                  dispatching a request.

  --all-methods                   Show HEAD and OPTIONS methods.
  --help                          Show this message and exit.

下面是一个输出示例(应用程序有很多蓝图,每个蓝图都有自己的路线)


(venv) C:\myapps\flask\helloflask>flask routes
Endpoint            Methods    Rule
------------------  ---------  ------------------------------------------
admin.index         GET        /admin/
admin.static        GET        /admin/public/static/admin/<path:filename>
auth.login          GET, POST  /auth/login
auth.logout         GET        /auth/logout
auth.register       GET, POST  /auth/register
auth.static         GET        /auth/public/static/auth/<path:filename>
blog.archive        GET        /blog/archive
blog.author         GET        /blog/author
blog.category       GET        /blog/category
blog.index          GET        /blog/
blog.static         GET        /blog/public/static/blog/<path:filename>
blog.tag            GET        /blog/tag
contact.index       GET, POST  /contact
contact.static      GET        /public/static/contact/<path:filename>
home.about          GET        /about
home.index          GET        /
home.static         GET        /public/static/home/<path:filename>
static              GET        /public/static/<path:filename>

现在检查 route/endpoint 是否被 Flask(或准确地说是 werkzeug)重新殖民。

现在,作为猜测,我认为您应该更改此行

            link = url_for('forgot_passwd', token=token, _external=True)

            link = url_for('sifremiunuttum', token=token, _external=True)

最后,我建议您查看代码。

我是这样改的,cizario说的

link = url_for('sifremiunuttum', token=token, _external=True)

当我以这种方式更改 app.route 部分时,我没有收到本地邮件错误。

@app.route('/sifremiunuttum/<token>',methods=['GET', 'POST'])