@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.routeting.BuildError:无法使用值["token"为端点"forgot_passwd"构建URL。您的意思是"注销"吗?
我看了一下html页面,似乎没有问题。我不明白问题出在哪里。
>flask
已经有一个强大的内置cli
命令来dump
应用程序的所有可用路由。
尝试flask --help
探索所有可用的flask
命令,如果有其他已安装的扩展(例如:db
用于flask-migrate
(。
尝试flask routes --help
以获取有关flask routes
命令的help
:
(venv) C:myappsflaskhelloflask>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:myappsflaskhelloflask>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)
最后,我建议您查看代码。
正如cizario所说,我以这种方式改变了它。
link = url_for('sifremiunuttum', token=token, _external=True)
当我以这种方式更改 app.route 部分时,我没有收到本地邮件错误。
@app.route('/sifremiunuttum/<token>',methods=['GET', 'POST'])