本文最后更新于:2023-11-07T09:49:04+08:00
体验地址: https://www.gishai.top/view/#/login
特别注意的是,当前文章的Django版本是3.1.4
使用social-auth-app-django
1
| pip install social-auth-app-django
|
settings中配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| INSTALLED_APPS = ( ... 'social_django', ... )
AUTHENTICATION_BACKENDS = ( 'social_core.backends.weibo.WeiboOAuth2', 'social_core.backends.qq.QQOAuth2', 'social_core.backends.weixin.WeixinOAuth2', 'users.views.CustomBackend', 'django.contrib.auth.backends.ModelBackend', )
SOCIAL_AUTH_POSTGRES_JSONFIELD = True SOCIAL_AUTH_URL_NAMESPACE = 'social' SOCIAL_AUTH_QQ_KEY = '123456' SOCIAL_AUTH_QQ_SECRET = 'd34c96123456789' SOCIAL_AUTH_QQ_USE_OPENID_AS_USERNAME = True
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/' SOCIAL_AUTH_TRAILING_SLASH = False
TEMPLATES = [ { ... 'OPTIONS': { ... 'context_processors': [ ... 'social_django.context_processors.backends', 'social_django.context_processors.login_redirect', ... ] } } ]
|
urls配置
1
| url('^accounts/', include('social_django.urls', namespace='social')),
|
QQ的配置
qq比较特别,其余的按照网上说明配置即可成功,下面着重说明QQ的一些配置.
先申请QQ互联地址->注册认证开发者->创建应用等待审核
特别注意
填写回调的时候需要注意
需要填写不带斜杠的地址,不然通过不了,说是回调地址不合法:须为http或https开头的子目录。如http://qq.com/mycb
特别感谢子钦加油
https://www.cnblogs.com/zmdComeOn/p/12667228.html
https://blog.csdn.net/weixin_39944891/article/details/94739204