django - Django:发送验证电子邮件后如何保存新的电子邮件地址
问题描述
我正在创建通过确认电子邮件验证新电子邮件地址的逻辑。但我不明白如何在发送验证电子邮件后保存新的电子邮件地址。我需要将新的电子邮件地址保存在某处,以便在用户检查验证电子邮件时保存它。验证逻辑通常如何工作?
我当前的代码是这样的
views.py
def change_email(request):
if request.method == 'POST':
form = ChangeEmailForm(request.POST)
if form.is_valid():
# send the verification email here while creating a token
...
to_email = form.cleaned_data.get('new_email')
email = EmailMessage(subject, message, to=[to_email],)
email.send()
return HttpResponseRedirect...
def verify_email(request, uid64, token):
# user verify the new email address when checking the verification email here but how I can save the new email address the user input
如何保存用户输入的新电子邮件地址或将新电子邮件地址值保存在表单上以便以后保存?
解决方案
扩展用户模型以添加一个附加字段“new_email”,然后在发送电子邮件之前将其保存。
def change_email(request):
if request.method == 'POST':
form1 = ChangeEmailForm(request.POST)
if form1.is_valid():
request.user.new_email = form.cleaned_data['new_email']
request.user.save()
...
推荐阅读
- javascript - 可枚举函数特别是 JavaScript 中的 .reduce() 函数
- scala - 如何堆叠两列进行分组?
- keras - 如何在 Keras 中为 Conv2D 设置 3D 过滤器?
- php - 为什么我在 codeigniter 中上传时看到错误消息?
- json - Issues while trying to form regex of Json string
- ibm-midrange - 将系列直接连接到大型机 (NDM) 设置
- react-native - 在两个不相关的组件之间进行通信
- bash - Grep not parsing the whole file
- cmake - How do I specify the files I want CPack to pack into an RPM?
- javascript - 检查从 iFrame 动态添加的类