如何在django中使用facebook登录和gmail登录?

如何在django中使用facebook登录和gmail登录?,django,Django,我需要根据我的应用程序安装获取用户信息。我想获取用户信息。我需要如何在gmail帐户中连接我的应用程序设置。它必须显示用户详细信息。首先,你需要在facebook gmail.install social_auth中创建应用程序id和应用程序机密。在settings.py中,必须在已安装的应用程序中包含social_auth FACEBOOK_APP_ID = 'your app id' FACEBOOK_API_SECRET = 'your secret key' SOCIAL_AUT

我需要根据我的应用程序安装获取用户信息。我想获取用户信息。我需要如何在gmail帐户中连接我的应用程序设置。它必须显示用户详细信息。

首先,你需要在facebook gmail.install social_auth中创建应用程序id和应用程序机密。在settings.py中,必须在已安装的应用程序中包含social_auth

FACEBOOK_APP_ID     = 'your app id'
FACEBOOK_API_SECRET = 'your secret key'
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY =''
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET =''

LOGGING = {
  'version': 1,
  'disable_existing_loggers': False,
   'filters': {
      'require_debug_false': {
        '()': 'django.utils.log.RequireDebugFalse'
    }
   },
  'handlers': {
     'mail_admins': {
         'level': 'ERROR',
         'filters': ['require_debug_false'],
         'class': 'django.utils.log.AdminEmailHandler'
     }
 },
 'loggers': {
     'django.request': {
         'handlers': ['mail_admins'],
         'level': 'ERROR',
         'propagate': True,
      },
   }
 }
AUTHENTICATION_BACKENDS = (
'social_auth.backends.facebook.FacebookBackend',
'social_auth.backends.google.GoogleOAuth2Backend',
'social_auth.backends.google.GoogleBackend',
'social_auth.backends.twitter.TwitterBackend',
)
LOGIN_REDIRECT_URL = '/'
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
url.py

url(r'', include('social_auth.urls')),
views.py

def home(request):
  if request.user.is_authenticated():
    return HttpResponseRedirect('done')
  else:
    return render_to_response('home.html',locals(),RequestContext(request))


@login_required
def done(request):
   return render_to_response('done.html',RequestContext(request))
def logout(request):
   auth_logout(request)
   return HttpResponseRedirect('/')
home.html文件

<li class="dext"><a href="/login/facebook/" rel="nofollow">Facebook</a></li>
<li class="dext"><a href="/login/google/" rel="nofollow">GoogleMail</a></li>
<li class="dext"><a href="/login/twitter/" rel="nofollow">Twitter</a></li>
  • done.html

    <table>
      <tr class="odd"><th>Id:</th> <td>{{ user.id }}</td></tr>
      <tr class="even"><th>Username:</th> <td>{{ user.username }}</td></tr>
      <tr class="odd"><th>Email:</th> <td>{{ user.email|default:"Not provided" }}</td></tr>
      <tr class="even"><th>First name:</th> <td>{{ user.first_name|default:"Not provided" }}</td></tr>
      <tr class="odd"><th>Last name:</th> <td>{{ user.last_name|default:"Not provided" }}</td></tr>
      <tr class="even"><th>Last login backend:</th> <td>{{ last_login }}</td></tr>
      </table>
    
    
    Id:{{user.Id}
    用户名:{{user.Username}
    电子邮件:{{user.Email}默认值:“未提供”}
    名字:{{user.First_name}默认值:“未提供”}
    姓氏:{{user.Last_name}默认值:“未提供”}
    上次登录后端:{Last_login}