我想知道如何生成自动激活密钥以连接到我的电子邮件激活链接 这是发送的链接:http://localhost:8001/sign_up/60/subsribe/14/confirmEmail 但为了更安全,我想发送类似:http://localhost:8001/sign_up/60/subsribe/14/confirmEmail/ {{activation_key}}
的内容mail = EmailMultiAlternatives("Confirmation d\'email pour finaliser votre inscripttion","pour finaliser votre inscription, veuillez consulter le lien ci-dessus ",from_email, to=[email]) mail.attach_alternative('http://localhost:8001/sign_up/' + str(id_account) + '/subscribe/' + str(id_sub) + '/confirmEmail',"text/html") mail.send()
答案 0 :(得分:3)
您可以使用Signer类来实现此目的。即
router.get('/:shotID(?:([a-f0-9]{24})(?:\.png)?$)', ...);
然后,您可以使用用户配置文件存储密钥。请求链接时,您可以执行以下操作:
from django.core.signing import Signer
signer = Signer()
signed_value = signer.sign(profile.user.email)#gives 'email@email.com:signed_things', extract signed_things'
key = ''.join(signed_value.split(':')[1:])
#send out key as part of url