DEV Community

Cover image for The complete django-allauth guide

The complete django-allauth guide

Gajesh on July 17, 2019

User registration and authentication is one of the most essential components of a web application. This tutorial deals with setup, configuration, a...
Collapse
 
treygec profile image
George Corple

Hi! Thanks for the obvious hard work you put into this. Tried working through it, and it wasn't working. Discovered that you need to add "SITE_ID =1" into your settings file and it all starts working.

Haven't gotten passed the initial setup, but looking forward to the rest!

Collapse
 
devanghingu profile image
Devang Hingu

why "SITE_ID =1" required?

Collapse
 
gajesh profile image
Gajesh

I will fix it. Thanks.

Collapse
 
vaneclavijo profile image
VaneClavijo

when I clik on Google login it redirects me to

Image description

and i want it to redirect me directly to provider login page

Collapse
 
nguepi profile image
Idriss Nguepi

I have This issue to,

Collapse
 
frederickteye profile image
Frederick-Teye

It is default, because the example project that allauth has has the same setup... They just customized it looks. I think that is the best thing for me to do at the moment.

Collapse
 
alfarosalvador profile image
Alfaro

Great blog. It helped a lot setting user authentication in place.

One recommendation, I would encourage users to create a "user authentication" app within the DJANGO project in order to have a cleaner main folder. Just a thought.

Collapse
 
af profile image
AF uarabei

Hi! How would I go about changing the way "Remember Me" checkbox is displayed?
I have tried this:

class UserLoginForm(LoginForm):
    def __init__(self, *args, **kwargs):
        super(UserLoginForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        # self.helper.form_show_labels = False # Doesn't work though it should

        self.fields["login"].label = ""
        self.fields["password"].label = ""

        self.fields["remember"].widget.attrs.update({
            "input": {
                "type": "checkbox",
                "name": "checkbox-fill-1",
                "id": "checkbox-fill-a1",
                "checked": "",
            },
        })
Enter fullscreen mode Exit fullscreen mode

But it does not seem to work. I want to have a custom "Remember me" checkbox that nothing I do changes it

Collapse
 
aakas profile image
aakas

I recently got into a issue where user cannot login whose facebook id is made using mobile number and no email address is connected to it.

Is it due to that i kept ACCOUNT_EMAIL_REQUIRED = True ?

looking forward for solution.

Collapse
 
mistermaker profile image
Mohit Aggarwal

How can i add custom phone number field in django allauth

Collapse
 
shivamrohilla profile image
Shivam Rohilla

I don't know why facebook integration is not working on my live website, it's perfectly run on localhost but not on live website, can you please explain how to assign a user profile while we signup through facebook, I have 2 user types and I want to assign them one user profile can you please tell me how to do this :)

Collapse
 
herchila profile image
Hernán Chilabert

Hey Gajesh, nice post!
Quick question: how can I exclude fields in my CustomSignUp view? Because, If I create my CustomSignUp adding some extra field (like 'role' or whatever), the username, email and password always are there.
Thanks!

Collapse
 
mralexwinkler profile image
Alex Winkler

Really nice in-depth tutorial. I was wondering if you've ever encountered a KeyError at /accounts/login/ 'BACKEND' issue and if so how did you resolve it? I've been trying to find a solution for over a week and just can't seem to resolve it.

Even posted a SOF question..

stackoverflow.com/questions/602517...

Collapse
 
jhoniewebappdev profile image
JhonieWebAppDev

this is great, but do you have a logical explanation why is the TEMPLATES setting is like this?

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', => # "same as below"
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request', => # "same as above"
],
},
},

]

is this necessary?
why not like this?
for it's more simple and understandable

============================================================

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.contrib.auth.context_processors.auth',
'django.template.context_processors.request', = > not "DRY"
'django.contrib.messages.context_processors.messages',
],
},
},
]

Collapse
 
programmingprobie profile image
programmingprobie

Has anyone had any success using it with DRF ?

Collapse
 
mik3yf profile image
Mike Farad

Is it possible to make the password field on the sign up page not required

Collapse
 
someab profile image
Ahmad Bilal

Correction: In the second code block the line "'django.template.context_processors.request'," is repeated twice.

Collapse
 
defidelity profile image
Amusat Haki Adeyemi

Thanks for this, I've been using Allauth for quite a long time and I still find this useful.

Collapse
 
ankitdevelops profile image
Ankit Kumar

How i can check if user's email is verified or not in django template.

Collapse
 
akashnagtilak profile image
Akash Nagtilak

Thanks

Collapse
 
butonix profile image
Butonix

how to do authorization in a modal window? So that the user does not have the opportunity to click on the link /account/login/ only through the modal window

Collapse
 
kamrulhasan12345 profile image
Mohammad Kamrul Hasan

Thanks for this deep tutorial

Collapse
 
coledrain profile image
ColeDrain

I know it's been a while, but 'django.template.context_processors.request' was repeated twice in the context_processors.

Collapse
 
devkranthi profile image
devkranthi

Can we use this for mobile client seeking Social Login?
What data should be expected from mobile client?

Collapse
 
devanghingu profile image
Devang Hingu

can i use same login pages for Staff ? And redirect staff user to different URL?

Collapse
 
parthindia48 profile image
Crypto Shorts

I downloaded latest repository and I had one error due to 'edx'.
I removed 'allauth.socialaccount.providers.edx', from settings.py and everything is working fine.

Collapse
 
parthindia48 profile image
Crypto Shorts

one more correction : in the top section "allauthallauth.account" is mentioned which is actully "allauth.account".

Collapse
 
fahadali profile image
Fahad Ali

Hello sir .I want to login with username or email like instagram then can i use allauth

Collapse
 
abdrrahim profile image
ABD RRAHIM • Edited

Thanks 🫡