[英]Get django user profile from python-social-auth
我的Django项目允许用户使用python-social-auth的django集成以Google或Facebook个人资料登录。
他们登录后,是否有办法在Google或Facebook上获得指向其个人资料的链接? 我正在尝试做这样的事情:
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import User
from django.core.mail import mail_admins
@receiver(post_save, sender=User)
def alert_new_user(sender, **kwargs):
instance = kwargs['instance']
social = instance.social_auth.last() # Assuming .last() gives me the one just added
if social is not None:
mail_admins('New user resistration',
'A new user registered with name {}'.format(instance.get_full_name()),
'<html><head/><body>A new user, <a href="{}">{}</a>, registered.</body></html>'.format(
???What goes here???, instance.get_full_name()
)
)
您可以在登录之前获得指向他们的Facebook个人资料的链接。
在pipeline
,有一个名为social_details
的函数,该函数从指定的社交网络获取有关用户的信息。
如果我们看一下这种方法,它非常简单:
def social_details(backend, details, response, *args, **kwargs):
return {'details': dict(backend.get_user_details(response),
**details)}
并且如果您print
response
:
def social_details(backend, details, response, *args, **kwargs):
print(response)
return {'details': dict(backend.get_user_details(response),
**details)}
您将看到有一个参数link
,前提是通过Facbook登录。 现在,您可以获取该link
并根据需要保存/使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.