Is There A Way To Send A User Email When User Object Is Created?
In the system I am building user CAN NOT register them selves. The users are added by one of the system admins. So there is no user registration form or view. The registration is o
Solution 1:
You can register a callback on the post_save signal for the User model. Somewhere along the lines of:
# note: untested codefrom django.db.models.signals import post_save
from django.contrib.auth.models import User
defemail_new_user(sender, **kwargs):
if kwargs["created"]: # only for new users
new_user = kwargs.["instance"]
# send email to new_user.email ..
post_save.connect(email_new_user, sender=User)
Note the if kwargs["created"]:
condition which checks if this is a newly created User instance.
Solution 2:
Use the post_save signal, which has a created
argument sent with the signal. If created is true, send your email.
Edit
Shawn Chin beat me to it. Accept his answer
Solution 3:
You can use the signals framework. A post-save signal on User objects will be appropriate, see here for a similar example.
Post a Comment for "Is There A Way To Send A User Email When User Object Is Created?"