Skip to content

Instantly share code, notes, and snippets.

@venkatesh22
Created June 26, 2013 05:37
Show Gist options
  • Save venkatesh22/5865016 to your computer and use it in GitHub Desktop.
Save venkatesh22/5865016 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)
@karatugo
Copy link

foo is a dummy name. Replace it with your own filename.

@stodge
Copy link

stodge commented Mar 16, 2018

What version(s) of Django does this support?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment