gpt4 book ai didi

python - 我如何发送带有确认链接的电子邮件以单击它?

转载 作者:行者123 更新时间:2023-11-28 23:03:09 25 4
gpt4 key购买 nike

模型.py:

class Users(models.Model):
username = models.CharField(max_length=255)
slug = models.CharField(max_length=255, default='0')
password = models.CharField(max_length=300)
passwordrepeat = models.CharField('Repeat Password', max_length=300)
password_token = models.CharField(max_length=300, default='0')
email = models.CharField(max_length=255)
email_verified = models.BooleanField(default=False)
email_token = models.CharField(max_length=255)
email_token_expiry = models.DateTimeField()
tos = models.BooleanField(default=False)
active = models.BooleanField(default=False)
last_login = models.DateTimeField(auto_now_add=True)
last_action = models.DateTimeField(auto_now_add=True)
is_admin = models.BooleanField(default=False)
role = models.CharField(max_length=255, default='0')
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now_add=True)

def __unicode__(self):
return self.username

class UsersModelForm(forms.ModelForm):
class Meta:
model = Users
fields = ('username', 'password', 'passwordrepeat', 'email')
widgets = {
'password' : PasswordInput(),
'passwordrepeat' : PasswordInput(),
}

views.py:

def register(request):
flag = True
possible = '0123456789abcdefghijklmnopqrstuvwxyz'
token = ''

current_datetime = datetime.datetime.now()

user = UsersModelForm()
if request.method == 'POST':
userf = UsersModelForm(request.POST)
username = userf.data['username']
password = userf.data['password']
passwordrepeat = userf.data['passwordrepeat']
email = userf.data['email']

password = bcrypt.hashpw(password,bcrypt.gensalt())
passwordrepeat = bcrypt.hashpw(passwordrepeat,bcrypt.gensalt())

userf.data['password'] = password
userf.data['passwordrepeat'] = passwordrepeat

if password != passwordrepeat:
flag = False
passVariable = {'user':user, 'flag': False}
return render_to_response('register.html', passVariable, context_instance=RequestContext(request))

elif password == passwordrepeat:
for i in range(1,10):
temp = random.choice(possible)
token = token + temp

print token
if userf.is_valid():
check = userf.save(commit=False)
check.email_token = token
check.email_token_expiry = current_datetime + timedelta(1)
check.save()
return HttpResponseRedirect('/')
else:
return render_to_response('register.html', {"user": user, 'flag': True}, context_instance=RequestContext(request))

将数据保存到表中后,我需要向用户发送该 token 以确认用于注册的电子邮件地址。我该怎么做?

如果有人帮助我修复它,我将不胜感激。

最佳答案

使用django registration ,它免费提供所有这些逻辑和更多内容。请注意,从一些 template examples 开始会更容易.

关于python - 我如何发送带有确认链接的电子邮件以单击它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8877855/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com