Skip to content

Instantly share code, notes, and snippets.

@ldonjibson
Forked from venkatesh22/django custom signal
Created May 6, 2020 09:26
Show Gist options
  • Save ldonjibson/8dc2a17846460f698410de7177f46b62 to your computer and use it in GitHub Desktop.
Save ldonjibson/8dc2a17846460f698410de7177f46b62 to your computer and use it in GitHub Desktop.
django custom signals creation example
#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