将编码的电子邮件令牌传递给flask方法

时间:2016-02-18 23:25:54

标签: python flask

我正在努力修改cookiecutter Flask应用。我尝试按https://realpython.com/blog/python/handling-email-confirmation-in-flask/添加电子邮件授权。

我的原始网页仅捕获电子邮件。然后,我想要求感兴趣的用户填写更大的表格以完成注册。

为此,我发送一封包含令牌中电子邮件的电子邮件,如下所示:

Welcome! Please follow this link to complete registration:

http://127.0.0.1:5000/register/?token=ImNsdWVtYXJpbmUxQG1haWxpbmF0b3IuY29tIg.CafSGw.5f9hjRwQDeDWmQu4--jYVgbzezw

然后我想捕获令牌并完成注册,例如:

@blueprint.route("/register/<token>", methods=['GET', 'POST'])
def register(token):
    form = RegisterForm(request.form, csrf_enabled=False)
    email = confirm_token(token) # decodes email from token
    # look up email here and save registration info to same user object as email
    if form.validate_on_submit():

然而,首先要做的事情是我需要捕获令牌。为什么链接不能将令牌传递给寄存器方法

1 个答案:

答案 0 :(得分:1)

"/register/<token>"的路由要求您的链接采用"http://127.0.0.1:5000/register/ImNsdWV...&#34;的形式,其中令牌是路径元素,而不是查询参数。

如果您要使用查询参数,以便您作为示例提供的网址有效,则需要使用"/register/"的路由,然后使用access令牌作为{{1}而不是将它作为参数传递给函数。