我被Django的身份验证弄得不知所措,并试图在一段时间内理解它。我使用了OAuth -auth-app-Django来获得GitHub和Facebook的授权。使用GitHub登录后,我检查了管理页面,GitHub工作了,脸书不工作,

在user social auths部分,我无法使用html页面中的模板语法访问提供者名称,没有显示出来!
有人能解释一下这里到底发生了什么吗?什么是关联和随机数?
这是我的html。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
{%if user.is_authenticated%}
<h1>{{user.provider}}</h1>
<h1>{{user.username}}</h1>
{%else%}
<h1>you are not logged in</h1>
{%endif%}
</body>
</html>发布于 2021-09-07 13:00:47
您可以通过执行以下操作来访问provider:
在views.py中
def get_provider(request):
user= request.user
user.social_auth.get(provider='provider name')
provs= ['github','twitter','facebook','google-oauth2'] # Any backend in the social auth back end
found=list()
notfound=list()
for prov in provs :
try:
user.social_auth.get(provider=prov)
print("Found ",prov)
found.append(prov)
except:
print(prov,"Not found ")
notfound.append(prov)
return render(request, 'registration/social_login.html', {
'found':found,
'not_found':notfound,
}) 然后在你的模板中
social_login.html
{% for element in found %}
<p>you are auth as {{element}}</p>
{% endfor %}
{% for el in not_found %}
<p>you are not auth in {{el}}</p>
{% endfor %}您可以在这里找到更多信息https://simpleisbetterthancomplex.com/tutorial/2016/10/24/how-to-add-social-login-to-django.html
https://stackoverflow.com/questions/67465759
复制相似问题