Python | Django-Allaut setup and configuration

This article covers settings and some basic configurations. Later we will deal with social DefaultAccountAdapter into the system, extending classes, and effectively using DefaultAccountAdapter to add custom processes.

This can be overwhelming for a beginner django or the new user djnago-allauth himself. While this is well documented, due to the lack of time and resources of the contributing developers, there weren't many articles and detailed tutorials in the library. So this series tries to solve this problem and make a comprehensive tutorial series to make django-allauth easy to use and work with for the django community.

How to set up?
You can download the files used in the tutorial, to gain an advantage. The following steps will guide you through the setup.

  • Create a Django project if you don't already have one.
  • Install django- allauth using pip install django-allauth
  • Add & # 39; allauth , allauth.account & # 39; , allauth.socialaccount and all required social accounts in INSTALLED_APPS. You can view the full list of supported APIs here . The login function is described in detail in the next article. Once configured, your installed applications should look similar as follows.


'django.contrib.admin ' ,

  ' allauth' ,

'allauth.account' ,

'allauth.socialaccount' ,

'allauth.socialaccount.providers .google' ,

'alla uth.socialaccount.providers.facebook' ,

' django.contrib.auth' ,

'django.contrib.sites' ,

  'django.contrib.contenttypes' ,

  'django.contrib.sessions' ,

  'django.contrib.messages' ,

  'django.contrib.staticfiles' ,


  • Configure the context processor settings template in and also add the URL pattern to the project


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





  • Add the following authentication backend.

    'django.contrib.auth.backends.ModelBackend' ,

    'allauth.account.auth_backends.AuthenticationBackend' ,

  • Copy the template files from the django-allauth repository or mine custom repository (i did some changes and some good structuring) and paste it to the templates folder of your project directory.
  • Add the Allaut urls to of your main project directory. After adding Allaut URL, below should look like this:
  • from django.contrib import admin

    from django.urls import path

    from django.conf.urls import url, include & lt; / code & gt; & lt; / pre & gt; 

    & lt; pre & gt; & lt; code & gt; urlpatterns = [

      path ( 'admin /' ,,

    url (r '^ accounts /' , include ( ' allauth.urls' )),


    • You can also add your own CSS or my CSS (well commented and documented) which I created while using the allauth templates. It includes styling for almost all pages, and even mobile-friendly email templates for confirming and resetting email passwords. You can do this by creating a static folder in your project directory and placing your CSS in the account folder.
    • Run python makemigrations and python migrate to complete any required migrations, and run python runserver to start the django server.
    • Follow URL patterns to display the registration form. 
      For example: localhost: 8000 / accounts / login to display the login page.

    Most django-allauth functions can be configured using built-in adapters and variables by placing them in the file. While the documentation has many such options with good explanations, some of them are highlighted below .

    • Email confirmation expiration date: Sets the number of days within which the account must be activated. For example: ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS=7
    • Email address required for activation: This parameter allows you to specify whether an email address is required for registration. Set False to disable the email requirement. For example: ACCOUNT_EMAIL_REQUIRED = True
    • Checking your email account. This parameter can be used to specify whether to check email for a user to log on after registering an account. You can use "required" to prevent the user from logging in until the email is confirmed. You can set optional to send email, but allow the user to log in without email. You can also set none to not send confirmation email. (Not recommended) For example: ACCOUNT_EMAIL_VERIFICATION = mandatory
    • Login Attempt Limit: This is an important feature that can be used to prevent brute force attacks on a user's login module. You can set the maximum number of login attempts and the user will be blocked from logging in until it times out. This function uses the ACCOUNT_LOGIN_ATTEMPTS_TIMEOUT setting. For example: ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5
    • Logon Attempt Limit Timeout: This parameter must be used if ACCOUNT_LOGIN_ATTEMPTS_LIMIT is used. The value is specified in seconds since the last failed login attempt. Please do not do it in a way that does not interfere with gross coercion. For example: ACCOUNT_LOGIN_ATTEMPTS_TIMEOUT = 86400 # 1 day in seconds
    • URL redirection for login and logout. When a user logs in or out, you can redirect the user to a specific URL or page, and you can use the following settings to set these values. By default, allauth redirects login to / accounts / profile / account / accounts / profile / URL and login to localhost localhost: 8000 or any home page localhost
      For example: ACCOUNT_LOGOUT_REDIRECT_URL = & # 39; / accounts / login / & # 39;
      For example: LOGIN_REDIRECT_URL = & # 39; / accounts / email / & # 39;

    Finally, your allauth settings should look similar to the settings below.

    # django-allauth registration settings





      # 1 day


    # or any other page

    ACCOUNT_LOGOUT_REDIRECT_URL = '/ accounts / login /'  

    # redirects to profile page if not configured.

    LOGIN_REDIRECT_URL = '/ accounts / email /'

    Recommendations :
    Django Allah official documentation
    My custom templates and CSS

Get Solution for free from DataCamp guru