Authentication System using Django-Allauth

Verdy Evantyo
2 min readJun 4, 2020

--

Hey guys! if you are making a new website, it must be a authentification system that can make a new user log in, sign up or log out in our website. As we know, django has a authentification system that could help us developing our website with django named django-allauth. This time i want to share about how to setup django-allauth in your django project.

Authentication system

Django-allauth instalation

First, open your terminal and then type :

pip install django-allauth

Django-allauth setup

Go to your settings.py, go to the bottom and type this code :

AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
]

Next, open your settings.py on your django project and then go to the INSTALLED_APPS and add this app :

'django.contrib.sites',

'allauth',
'allauth.account',
'allauth.socialaccount',

Still on the settings.py, go to the bottom and type this code :

SITE_ID = 1

Next, go to main urls.py on your django project, we add a path to access django authentification by typing this path in urlpatterns :

path('accounts/', include('allauth.urls')),

Go back to your settings.py and type a login redirect so if we want to log in, it will be redirect to some of your page. For example, i am making a blog website and then i want to direct a user to login on my blog page on my blog website. Type this loginn redirect below the WSGI_APPLICATION on settings.py :

LOGIN_REDIRECT_URL = '/blog'

Last is do the makemigrations and migrate, and you have your authentication systems. If you want to connect this authentication for example your navbar or something else, type {% url ‘account_login’ %} for login page {% url ‘account_logout’ %} for logout page, {% url ‘account_signup’ %} for signup page on your href on html page.

--

--