在 Django 中更改用户电子邮件而不使用 django-profiles
在我的 Django 应用程序中,我希望用户能够更改电子邮件地址。我已经看到 StackOverflow 的解决方案将人们指向 django-profiles。不幸的是,我不想使用成熟的配置文件模块来完成更改用户电子邮件的微小壮举。有谁在任何地方看到过这个实施吗?在这种情况下,通过发送确认电子邮件来验证电子邮件地址的过程是必需的。
我花了很多时间试图找到一个有效的解决方案,但没有成功。
干杯。
In my Django application I would like the user to be able to change the email address. I've seen solution of StackOverflow pointing people to django-profiles. Unfortunately I don't want to use a full fledged profile module to accomplish a tiny feat of changing the users email. Has anyone seen this implemented anywhere. The email address verification procedure by sending a confirmation email is a requisite in this scenario.
I've spent a great a deal of time trying to a find a solution that works but to no avail.
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
电子邮件地址属于用户模型,因此无需使用配置文件来让用户更新其电子邮件。从用户模型创建一个 模型表单 email 作为字段,然后在您的视图中提供该表单并进行处理。类似于:
请注意,如果表单成功,我将返回 HttpResponseRedirect 以将用户发送到另一个页面。在本例中,我从 urls 文件中查找命名的 url。
The email address belongs to the user model, so there's no need to use profiles to let users update their email. Create a model form from the user model that has only email as a field, then provide that form in your view and process it. Something like:
Note that if the form is successful, I'm returning a HttpResponseRedirect to send the user to another page. In this case, I'm looking up a named url from my urls file.
看来是有人自己写的。它允许用户更改他们的电子邮件地址并发送确认电子邮件。
django-emailchange
Seems that someone did write their own. It allows users to change their email addresses and sends confirmation emails.
django-emailchange
不太确定这是否是 Django 1.4 的新要求,但我尝试了 Tom 的建议:
并收到字段错误。每个字段后面必须有一个尾随逗号(或者这就是解决我的错误的原因):
解决了问题
Not quite sure if it's a new requirement of Django 1.4 but I tried Tom's suggestion:
and got a fields error. You must have a trailing comma after each field (or so that's what solved my error):
fixed the problem