欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

DJANGO-ALLAUTH社交用户系统的安装配置

程序员文章站 2022-12-13 16:27:58
django-allauth是github上面排名较高的django user系统.本来通过对比是想选用django-userea的,可是博主智商不够看懂它的安装配置文档....

django-allauth是github上面排名较高的django user系统.本来通过对比是想选用django-userea的,可是博主智商不够看懂它的安装配置文档.....搞乱了一个测试项目之后,只好作罢.好在allauth安装配置相对简单.但是它的文档写得更乱...很多关键信息居然是在常见问题里面找到...记录下来备忘.

1.安装:

复制代码 代码如下:

pip install django-allauth

2.配置

settings.py

复制代码 代码如下:

template_context_processors = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
#"django.contrib.messages.context_processors.messages"
# required by allauth template tags
"django.core.context_processors.request",
# allauth specific context processors
"allauth.account.context_processors.account",
"allauth.socialaccount.context_processors.socialaccount",
)

authentication_backends = (
# needed to login by username in django admin, regardless of `allauth`
"django.contrib.auth.backends.modelbackend",

# `allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.authenticationbackend",
)

installed_apps = (
...
# the django sites framework is required
'django.contrib.sites',

'allauth',
'allauth.account',
'allauth.socialaccount',
# ... include the providers you want to enable:
'allauth.socialaccount.providers.amazon',
'allauth.socialaccount.providers.angellist',
'allauth.socialaccount.providers.bitbucket',
'allauth.socialaccount.providers.bitly',
'allauth.socialaccount.providers.coinbase',
'allauth.socialaccount.providers.dropbox',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.flickr',
'allauth.socialaccount.providers.feedly',
'allauth.socialaccount.providers.github',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.hubic',
'allauth.socialaccount.providers.instagram',
'allauth.socialaccount.providers.linkedin',
'allauth.socialaccount.providers.linkedin_oauth2',
'allauth.socialaccount.providers.openid',
'allauth.socialaccount.providers.persona',
'allauth.socialaccount.providers.soundcloud',
'allauth.socialaccount.providers.stackexchange',
'allauth.socialaccount.providers.tumblr',
'allauth.socialaccount.providers.twitch',
'allauth.socialaccount.providers.twitter',
'allauth.socialaccount.providers.vimeo',
'allauth.socialaccount.providers.vk',
'allauth.socialaccount.providers.weibo',
'allauth.socialaccount.providers.xing',
...
)

urls.py:

复制代码 代码如下:

urlpatterns = patterns('',
...
(r'^accounts/', include('allauth.urls')),
...
)

到此配置好了settings和url,在terminal里面输入

复制代码 代码如下:

python manage.py makemigrations
python manage.py migrate

3.初始化使用

启动本地服务器,后 登陆admin

将用户系统将要服务的网站id确定为当前设置里面设置的网站id
为每一个oauth登陆的接口设置一个socialaccount app
将site和接口提供商的信息填入

此时访问


如果之前登陆过 请先访问

就可以看到没有css的默认登陆页面了.可以重写,代码在

path\to\your\virtualenv\lib\site-packages\allauth\templates
各个社交网站接口提供商设置在此

比较本地化的只有微博和live...github可以算么 o(∩_∩)o

以上就是个人对于django-allauth的使用经验及配置,如有错误,还请指正