django电子邮件帐户活动

时间:2017-03-05 18:18:39

标签: django email

我正在向包含uuidd(activation_token)的用户发送激活电子邮件,当用户点击电子邮件中的链接时,我找不到eroror 404页面。

电子邮件代码

accountactivation = AccountActivation(
                        email=email,
                        password=password
                    )
                accountactivation.save()
        subject = 'Account Confirmation'
            contact_message = 'please click the link to activate your account' + 'http://127.0.0.1:8000/accounts/account_activation/?activation_token=%s' %(accountactivation.activation_token)
            from_email = settings.EMAIL_HOST_USER
            to_email = from_email
            send_mail(subject,
                    contact_message,
                    from_email,
                    [to_email],
                    fail_silently=False,
                    )

url pattern

 url(r'^account_activation/(?P<activation_token>[0-9A-Za-z])/$', views.account_activation, name="account_activation"), 

uuid代码示例

51094a477a14-4e26a7c84bff8b63a94d

浏览器中的网址

http://127.0.0.1:8000/accounts/account_activation/?id=51094a477a14-4e26a7c84bff8b63a94d/

1 个答案:

答案 0 :(得分:1)

您的激活令牌不接受连字符,并且只匹配单个字符。它应该是:

(?P<activation_token>[0-9A-Za-z-]+)

请注意,您可以将其从a-z更改为-f,因为该标记是一个uuid。