Installation configuration of django allauth social user system

  • 2020-04-02 14:21:47
  • OfStack

Django-allauth is a highly ranked DJANGO user system on github. Originally, I wanted to use django-userea through comparison, but the blogger was not intelligent enough to understand its installation and configuration documents. Fortunately, the allauth installation configuration is relatively simple. But its documentation is even messier... A lot of the key information was found in the FAQ... Take notes.

1. Installation:


pip install django-allauth

2. The configuration

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')),
...
)

So I'm going to go ahead and configure the Settings and the url, and I'm going to type in terminal


python manage.py makemigrations
python manage.py migrate

3. Initialize the use

Start the local server and log in admin

Identifies the site id that the user system will serve as the site id set in the current Settings
Set up a socialaccount app for each oauth login interface
Fill in the information about the site and the interface provider

At this time to visit

(link: http://127.0.0.1:8000/accounts/login/)
Please visit if you have logged in before
(link: http://127.0.0.1:8000/accounts/logout/)
You can see the default landing page without CSS. You can rewrite the code in

The PATH/TO/YOUR \ VIRTUALENV \ Lib \ site - packages \ allauth \ templates
The various social network interface providers are set here
(link: http://django-allauth.readthedocs.org/en/latest/providers.html)
Only weibo and live... Github can compute O( studying _ studying )O

The above is personal experience and configuration of django-allauth, if there is an error, please correct


Related articles: