• Home
  • Subscribe
  • Contribute Us
    • Share Your Interview Experience
  • Contact Us
  • About
    • About CSEstack
    • Campus Ambassador
  • Forum & Discus
  • Tools for Geek
  • LeaderBoard
CSEstack

What do you want to Learn Today?

  • Programming
    • Tutorial- C/C++
    • Tutorial- Django
    • Tutorial- Git
    • Tutorial- HTML & CSS
    • Tutorial- Java
    • Tutorial- MySQL
    • Tutorial- Python
    • Competitive Coding Challenges
  • CSE Subject
    • (CD) Compiler Design
    • (CN) Computer Network
    • (COA) Computer Organization & Architecture
    • (DBMS) Database Management System
    • (DS) Data Structure
    • (OS) Operating System
    • (ToA) Theory of Automata
    • (WT) Web Technology
  • Interview Questions
    • Interview Questions- Company Wise
    • Interview Questions- Coding Round
    • Interview Questions- Python
    • Interview Questions- REST API
    • Interview Questions- Web Scraping
    • Interview Questions- HR Round
    • Aptitude Preparation Guide
  • GATE 2022
  • Linux
  • Trend
    • Full Stack Development
    • Artificial Intelligence (AI)
    • BigData
    • Cloud Computing
    • Machine Learning (ML)
  • Write for Us
    • Submit Article
    • Submit Source Code or Program
    • Share Your Interview Experience
  • Tools
    • IDE
    • CV Builder
    • Other Tools …
  • Jobs

[Error Fixed] How to Get SITE_ID for Allauth Authentication in Django?

Aniruddha Chaudhari/702/0
Django

If you are using allauth Django authentication library, it is necessary to set the SITE_ID in the Django project setting.

I was using this library to set the Django social login authentication in one of my Python projects. I read many of the tutorials on the internet to get the site ID. Almost all the tutorials were claiming to try random numbers.

It’s cumbersome to change the site ID in the setting and run the application again. If it fails try with a new site ID and repeat the process again. This is really bullshit. Don’t do it.

Further, if you give the wrong SITE_ID for allauth and execute Django runserver. You will get an error saying…

Error :  `SocialApp matching query does not exist.

Without fixing this error, you can implement authentication.

Here is the hack to get SITE_ID for allauth and to solve this problem.

Method 1: Using Django Admin

Follow the steps below to get the site ID.

  • Login into the Django administrations dashboard. (Use your superuser account to login).
    If you are using localhost, open url 127.0.0.1:8000/admin/ in your browser and login.
  • Select Sites from SITES in the left sidebar.
  • Select desired site. Here I’m choosing 127.0.0.1:8000
  • Check the URL, you will see the site ID.
get SITE_ID for Allauth

Note:

  • You can use the same dashboard to add a new site for authentication.
  • By default, you will also see the example.com as a site listed in the sites. You can simply remove it.

Method 2: Using Django Shell

You can also use the Django interactive shell to get the SITE_ID for any website. Couple of commands you need to execute.

# python manage.py shell
Python 3.6.9 (default, Dec  8 2021, 21:08:43)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)

>>> from django.contrib.sites.models import Site
>>> new_site = Site.objects.create(domain='127.0.0.1:8000', name='127.0.0.1:8000')
>>> print(new_site.id)
3

Just replace the domain and name for the desired site.

Here the id for the mentioned site is 3.

This is a simple and very useful hack to get the SITE_ID for allauth for any website that uses allauth Django authentication library.

Python Interview Questions eBook

Django
Aniruddha Chaudhari
I am complete Python Nut, love Linux and vim as an editor. I hold a Master of Computer Science from NIT Trichy. I dabble in C/C++, Java too. I keep sharing my coding knowledge and my own experience on CSEstack.org portal.

Your name can also be listed here. Got a tip? Submit it here to become an CSEstack author.

Leave a Reply Cancel reply

Prerequisite for Django

Learn Python Basics

Django Tutorials

Why Django?

Django- Create Your First Project

Django- Adding CSS/Static Files

Django- Use/Load Static Files

Django- Create Form

Django- Create Input-Tags

Django- Display Message on Form Submit

Django- MultipleChoiceField in Form

Django- Read Model Data (order_by)

Django- Read First/Last Queryset Object

Django- Update Model Field

Django- Signals

Django- Create TextField in Form

Django- Add Model to Admin Site

Django- Customize Admin Site

Django- Understanding Model User

Django- Registration/Signup Form

Django- Form Layout with Widget-Tweaks

Django- OneToOneField in Model

Django- Foreign Key & Reverse Lookup

Django- Custom Template Filters

Django- Interactive Shell

Django- Social Login

Django- Deploy and Host [FREE] 🔥

© 2022 – CSEstack.org. All Rights Reserved.

  • Home
  • Subscribe
  • Contribute Us
    • Share Your Interview Experience
  • Contact Us
  • About
    • About CSEstack
    • Campus Ambassador
  • Forum & Discus
  • Tools for Geek
  • LeaderBoard