How can I trigger a function when a user registers in django?

sinaj

I took over a django web app and am still relatively new to django. I want to trigger a function whenever a new user registers on the website. But there is no code in the project to process the user registration. It all seems to happen under the hood. So I don't know where could put such a function call. The web app uses django.contrib.auth.

Additionally: How can I trigger a function when an account is activated?

kaajavi

You can use the signals to trigger an event when you save anything in your db, include the User from auth. You can see the django doc about this.
In your case, I think that the best way is like:

from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth import user


@receiver(post_save, sender=User)
def user_saved(sender, instance, **kwargs):
    ...

In the kwargs you can see, for example, if object is created or modified. The sender is the Class and the instance is the object.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

PHP When a user registers, How do I add their details to the end of an existing CSV file?

分類Dev

How can I get the user whom changed a file with a watchman trigger?

分類Dev

How can I update a user field using this function on sign up in django?

分類Dev

How can I trigger a function by clicking a div which is hidden in JavaScript?

分類Dev

How can I call a JS function when the user cancels the authorization check in the Google API?

分類Dev

How can I trigger save target as when click files on IE11?

分類Dev

Arangodb: Can I call a user function from a user function?

分類Dev

How do I trigger a build in Jenkins, with Git push to SCM-manager, when Jenkins does not allow anonymous user?

分類Dev

In Django, after a login how can I detect which auth backend authenticated the user?

分類Dev

How can I get the current user's group in forms.py in Django?

分類Dev

How can django redefine DJANGO_SETTINGS_MODULE when I run tests?

分類Dev

When should I use a lazy function in Django

分類Dev

How can I Execute/Call a user-space defined function from Linux kernel space module?

分類Dev

How can I apply a function to every row of a data frame in R when the function requires multiple inputs?

分類Dev

Laravel 5.7 - How can I show email verification redirect page when the user is not logged in?

分類Dev

How can I hide notification, when user select option from my PreferenceActivity(SettingActivity)

分類Dev

How can i make text in header Smaller when user scroll down?

分類Dev

How can I wire up a button on my page so that it is clicked when a user presses enter?

分類Dev

How can I catch an exception in Kotlin coroutine when I am awaiting it in another function?

分類Dev

How can I trigger `$on` events in AngularJS Karma unit tests?

分類Dev

How can I animate bound data from an event trigger?

分類Dev

How can I get the data of this user by clicking?

分類Dev

How can i link a user input to a string

分類Dev

How to know the values of CR registers from linux user and kernel modes

分類Dev

How can I know that my CPU shares the vector registers among the cores or each core has its private ones

分類Dev

I can get my script to run when the user clicks on the correct div, but how can I get it to run when the div simply becomes visible on the browser?

分類Dev

When a message fails to process in a ServiceBusTrigger Azure Function, how can I delay processing the same message for x minutes?

分類Dev

An expression in a function is not evaluating to true when it should. How can I fix this?

分類Dev

How can I, in C++, write a templated RAII wraper with custom function calls when functors are not an option?

Related 関連記事

  1. 1

    PHP When a user registers, How do I add their details to the end of an existing CSV file?

  2. 2

    How can I get the user whom changed a file with a watchman trigger?

  3. 3

    How can I update a user field using this function on sign up in django?

  4. 4

    How can I trigger a function by clicking a div which is hidden in JavaScript?

  5. 5

    How can I call a JS function when the user cancels the authorization check in the Google API?

  6. 6

    How can I trigger save target as when click files on IE11?

  7. 7

    Arangodb: Can I call a user function from a user function?

  8. 8

    How do I trigger a build in Jenkins, with Git push to SCM-manager, when Jenkins does not allow anonymous user?

  9. 9

    In Django, after a login how can I detect which auth backend authenticated the user?

  10. 10

    How can I get the current user's group in forms.py in Django?

  11. 11

    How can django redefine DJANGO_SETTINGS_MODULE when I run tests?

  12. 12

    When should I use a lazy function in Django

  13. 13

    How can I Execute/Call a user-space defined function from Linux kernel space module?

  14. 14

    How can I apply a function to every row of a data frame in R when the function requires multiple inputs?

  15. 15

    Laravel 5.7 - How can I show email verification redirect page when the user is not logged in?

  16. 16

    How can I hide notification, when user select option from my PreferenceActivity(SettingActivity)

  17. 17

    How can i make text in header Smaller when user scroll down?

  18. 18

    How can I wire up a button on my page so that it is clicked when a user presses enter?

  19. 19

    How can I catch an exception in Kotlin coroutine when I am awaiting it in another function?

  20. 20

    How can I trigger `$on` events in AngularJS Karma unit tests?

  21. 21

    How can I animate bound data from an event trigger?

  22. 22

    How can I get the data of this user by clicking?

  23. 23

    How can i link a user input to a string

  24. 24

    How to know the values of CR registers from linux user and kernel modes

  25. 25

    How can I know that my CPU shares the vector registers among the cores or each core has its private ones

  26. 26

    I can get my script to run when the user clicks on the correct div, but how can I get it to run when the div simply becomes visible on the browser?

  27. 27

    When a message fails to process in a ServiceBusTrigger Azure Function, how can I delay processing the same message for x minutes?

  28. 28

    An expression in a function is not evaluating to true when it should. How can I fix this?

  29. 29

    How can I, in C++, write a templated RAII wraper with custom function calls when functors are not an option?

ホットタグ

アーカイブ