-
-
Save ldonjibson/8dc2a17846460f698410de7177f46b62 to your computer and use it in GitHub Desktop.
django custom signals creation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#signals.py | |
from django.dispatch import Signal | |
user_login = Signal(providing_args=["request", "user"]) | |
#views.py | |
from foo import signals | |
def login(request): | |
... | |
if request.user.is_authenticated(): | |
signals.user_login.send(sender=None, request=request, user=request.user) | |
#tasks.py | |
from foo.signals import user_login | |
def user_login_handler(sender, **kwargs): | |
"""signal intercept for user_login""" | |
user = kwargs['user'] | |
... | |
user_login.connect(user_login_handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment