python-3.x - werkzeug.routing.BuildError:无法使用值 ['token'] 为端点“forgot_passwd”构建 url。您的意思是“注销”吗?
问题描述
@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: could not build url for endpoint 'forgot_passwd' with values ['token']。您的意思是“注销”吗?
我看了一下html页面,好像没有问题。我不明白问题出在哪里。
解决方案
flask
已经为您的应用程序的所有可用路由提供了强大的内置cli
命令。dump
尝试flask --help
探索所有可用的命令,flask
如果有的话,可能还有其他已安装的扩展(例如:db
for flask-migrate
)。
尝试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>
现在检查该路由/端点是否被重新殖民Flask
(或者werkzeug
准确地说)。
现在,作为一个猜测,我认为你应该改变这条线
link = url_for('forgot_passwd', token=token, _external=True)
至
link = url_for('sifremiunuttum', token=token, _external=True)
最后,我建议您查看代码。
推荐阅读
- sql - 使用 SQL 将 MS Access 信息返回到 Excel 电子表格
- php - Symfony 没有用户令牌,或者您忘记将控制器放在防火墙后面 @Security
- google-apps-script - 我如何显示带有超链接的图像?
- php - 使用 hubspot api 的 PHP curl 代码适用于多个订单,但有时会突然失败而没有任何响应
- python - 收敛到相同种群的遗传算法的交叉
- python - 如何获得上述人物的 3D 图?
- c# - ASP.NET Core 5.0 - 带颜色的全尺寸列
- mysql - 我可以根据按值分组为我的计数添加条件吗
- salesforce - docusign 签名的信封在 Salesforce 中保存了两次
- c# - DataTable 到 Html 表在 Gmail 上作为邮件发送