DJANGO-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和接口提供商的信息填入
此时访问
http://127.0.0.1:8000/accounts/login/
如果之前登陆过 请先访问
http://127.0.0.1:8000/accounts/logout/
就可以看到没有css的默认登陆页面了.可以重写,代码在
PATH\TO\YOUR\VIRTUALENV\Lib\site-packages\allauth\templates
各个社交网站接口提供商设置在此
http://django-allauth.readthedocs.org/en/latest/providers.html
比较本地化的只有微博和live...github可以算么 O(∩_∩)O
以上就是个人对于Django-allauth的使用经验及配置,如有错误,还请指正
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
相关文章
相关视频
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
推荐阅读
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论