DEV Community


Django: Allauth

Full stack dev to be, Using this platform to share and also document my 100 days coding challenge.
・2 min read

Up until now we haven't created any registration/login form. We could or should roll our own for a very special business requirement or we could use a ready made and famous authentication packages call django-allauth. Django allauth will handle all your login/registration need, and include plugins for login using 3rd party Oauth such as google, facebook, twitter, github to name a few. For more 3rd party authentication that Allauth support please refer here.

Lets start will installation of Allauth

Installing Django-Allauth

Installing django Allauth with the following command in your terminal

pipenv install django-allauth
pipenv lock -r > requirement.txt
Enter fullscreen mode Exit fullscreen mode

after the installation is done, We need to register django-allauth.

Settings Django-Allauth

Django-Allauth require a significant change to your file, Lets first check each part one by one ...

open your file, and first check your INSTALLED_APP, and include the following

    # Make sure the following 3 is installed

    # Django-allauth
Enter fullscreen mode Exit fullscreen mode

then add the following in your file

    # Needed to login by username in Django admin, regardless of `allauth`

    # Django-allauth
    # `allauth` specific authentication methods, such as login by e-mail

Enter fullscreen mode Exit fullscreen mode

once done, we should now update the file


lets now open file and add the following

urlpatterns = [
    path('account/', include('allauth.urls')),
Enter fullscreen mode Exit fullscreen mode

Optional Configuration

The following would be optional configuration that you could add to change the behavior of django_allauth, first open your file and add the following

# Common Django Settings
LOGIN_URL = "account/login"

# Django-allauth
Enter fullscreen mode Exit fullscreen mode

since we also added email verification mandatory, we need djnago to have an email backend

Configuring Django Email Backend

for testing purposes, its often better to use the console backend like so

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
Enter fullscreen mode Exit fullscreen mode

but for me, I prefer to use the file backend as it will create a proper html file for our emails

EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = BASE_DIR.joinpath('test').joinpath('email')
Enter fullscreen mode Exit fullscreen mode

and create a folder directory like so


Migrate your database

Django allauth require that you migrate its files with the command

python migrate
Enter fullscreen mode Exit fullscreen mode

you could now go to

register page



Congratulation, now your are able to register, and login your user using django-allauth

Discussion (0)