Last Updated : 24 May, 2024
User registration is one of the most essential parts of a web application.
django-registration-redux
and
django-alluth
are the most famous registration apps available in Django. This tutorials series deals with setup, configuration, and customization of
django-allauth
and serve as a guide for new users who want to get started quickly with
allauth
and make useful customizations along the way without much pain. This article covers setup and some basic configurations. Later, we will deal with social login, extending classes and efficient use of
DefaultAccountAdapter
to add custom process. It can be overwhelming to a
django
novice or a new user of
django-allauth
itself. Although it is well documented, due to time and resource constraints of the developers involved, there has not been many articles and in-depth tutorials on the library. So this series tries to solve that problem and make a comprehensive series of guides to make
django-allauth
easy to use and work with for the django-community.
How to Setup?You can
downloadthe files used in the tutorial to get a head start. The steps below guide you through the setup.
django-allauth
using the command pip install django-allauth
'allauth
, allauth.account'
, allauth.socialaccount
and all the necessary social logins to INSTALLED_APPS.
You can view the entire list of supported API's here. The Social login feature is described in detail in the next article. After you configure your installed apps should be similar as given below.
INSTALLED_APPS = [
'django.contrib.admin',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.facebook',
'django.contrib.auth',
'django.contrib.sites',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
template
context processor settings in settings.py
and also add URL pattern in the project urls.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.normpath(os.path.join(BASE_DIR, 'templates')),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
],
},
},
]
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
templates
folder in your project directory.urls.py
of your main project directory. After adding the allauth urls the below should look like,
from django.contrib import admin
from django.urls import path
from django.conf.urls import url, include
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^accounts/', include('allauth.urls')),
]
static
folder in the project directory and placing the CSS in account
folder.python manage.py makemigrations
and python manage.py migrate
to run all the necessary migrations and run python manage.py runserver
to start the django server.localhost:8000/accounts/login
to display the login page.settings.py.
file. Although the documentation has tons of such options with good explanations, highlighted some important ones below.
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS=7
False
to disable email requirement. Eg: ACCOUNT_EMAIL_REQUIRED = True
optional
for sending the email but allowing the user to login without an email. You can also set none
to not send any verification email. (Not Recommended) Eg: ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_LOGIN_ATTEMPTS_TIMEOUT
setting. Eg: ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5
ACCOUNT_LOGIN_ATTEMPTS_LIMIT
setting. The value set is in seconds from last unsuccessful login attempt. Please do not that this does not prevent admin login from being brute forced. Eg: ACCOUNT_LOGIN_ATTEMPTS_TIMEOUT = 86400 # 1 day in seconds
/accounts/profile/
URL and logout to the localhost:8000
or any localhost
homepage. Eg : ACCOUNT_LOGOUT_REDIRECT_URL ='/accounts/login/'
Eg : LOGIN_REDIRECT_URL = '/accounts/email/'
allauth
settings should look similar to the below settings. Python3
#django-allauth registraion settings
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS =1
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5
# 1 day
ACCOUNT_LOGIN_ATTEMPTS_TIMEOUT = 86400
#or any other page
ACCOUNT_LOGOUT_REDIRECT_URL ='/accounts/login/'
# redirects to profile page if not configured.
LOGIN_REDIRECT_URL = '/accounts/email/'
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4