I need to check information in user and request models while user logging in, so I've wrote this code using django signals:
from django.contrib.auth.signals import user_logged_in
def on_login(sender, user, request, **kwargs):
...
user_logged_in.connect(on_login)
How can I have access to the request while user registering? I've wrote this code, so I have access to user model, but not to request:
from django.db.models.signals import post_save
def on_registration(sender, user, created, **kwargs):
if created:
...
post_save.connect(on_registration, sender=settings.AUTH_USER_MODEL, dispatch_uid="create_user_profile")
Can I do that without using 3-rd party applications?
写一个装饰器并应用到您的函数中。然后,您可以在执行视图之前或之后注入您想要的任何代码。您也可以避免使用信号和第三方应用程序。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.