在Django管理员中激活用户后发送电子邮件 [英] Sending emails when a user is activated in the Django admin

查看:42
本文介绍了在Django管理员中激活用户后发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将要创建一个监视注册的站点,因为只有某些人可以注册.毫无疑问,尽管我在报名表上方写了任何文字,但仍有一些不适合的人会报名,所以我们要节制.

I'm about to create a site that has monitored registration in that only certain people are allowed to register. Undoubtedly some misfits will register despite any writing I put above the registration form so we're going with moderation.

注册后,将创建 django.contrib.auth User 和个人资料,并将电子邮件发送给主持人.主持人将登录Django管理站点,检查他们是否被允许注册并标记其帐户有效.如果他们不道德的尝试进入该帐户,则该帐户将被删除.

Upon registration a django.contrib.auth User and profile will be created and an email will be sent to the moderator. The moderator will log into the Django admin site, check they're somebody who is allowed to register and mark their account active. If they're some miscreant trying to slip in, the account would be deleted.

我将使用Recaptcha尝试停止自动尝试.

I'll use recaptcha to try and stop automated attempts.

当帐户被激活或删除时,我想发出一封电子邮件,以使帐户持有人知道他们的帐户发生了什么,他们可以登录,或者让他们知道我们要做什么他们应该不再傻了.

I would like to fire off an email when an account is activated or deleted to let the account holder know what has happened to their account and that they can either log in, or let them know we know what they're up to and they should stop being silly.

我怀疑这与信号有关,但坦白地说,我不知道这实际上适合什么地方,因为我正在使用从 django.contrib.auth .

I suspect this has something to do with signals but I frankly don't have a clue where this would actually fit in, given that I'm using a prefab model provided from django.contrib.auth.

任何技巧,线索或代码都可以被宽容地接受.

Any tips, clues or code are all graciously accepted.

推荐答案

您想看看信号.

  • 激活帐户后,您应该使用
  • When the account is activated, you should use a pre_save. You can compare the current User with the existing instance at the database: check that the instance exists, check the previous was active=False, check that the new one is active=True, then send an email.
  • When the account is deleted, use a pre_delete. If you use a post_delete you won't be able to access to the email.

这篇关于在Django管理员中激活用户后发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆