T
T
Tyrion Lannister2017-07-04 02:26:33
Django
Tyrion Lannister, 2017-07-04 02:26:33

How to set an action when creating a user in Django?

It is necessary that after each creation of a new user User, my function is called. Is it possible to implement this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor Che, 2017-07-04
@chewarer

Signals

E
Eugene, 2017-07-04
@immaculate

Depends on your requirement. There is more than one way to do this.
If you create users yourself (without using django-allauth and similar libraries), in one view, then it is enough to perform an action in this view.
Otherwise, you can either override the save method of your user class (I hope you're not using the idiotic crutch with Django's built-in django.contrib.auth.models.Users class and its associated Profile, but use your user model), or use a signal like , post_save.
In the case of using django-allauth, it has its own signals and hooks to implement such functionality.

I
Ivan, 2017-07-04
@ATNC

Here is a good tutorial on signals. You can use it
https://simpleisbetterthancomplex.com/tutorial/201...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question