54

I'm using django-allauth, and I configured localhost:9000/admin/ with the following details:

socialapp .
provider:
Name:
Client id:
App ID, or consumer key
Key:
Secret:  etc .

I set SITE_ID = 2 (because I changed the default site example.com to localhost:9000)

In settings.py:

   INSTALLED_APPS = (
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sites',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'django.contrib.admin',
        'uni_form',
        'allauth',
        'allauth.account',
        'allauth.socialaccount',
        'bootstrapform',
        # 'allauth.socialaccount.providers.twitter',
        # 'allauth.socialaccount.providers.openid',
         'allauth.socialaccount.providers.facebook',
    )
    SOCIALACCOUNT_PROVIDERS = \
        { 'facebook':
            { 'SCOPE': ['email', 'publish_stream'],
              'AUTH_PARAMS': { 'auth_type': 'reauthenticate' },
              'METHOD': 'oauth2' ,
              'LOCALE_FUNC': 'path.to.callable'} }

When I go to:

http://localhost:9000/accounts/facebook/login

I get:

Error :  `SocialApp matching query does not exist.

What am I doing wrong?

8 Answers 8

80

Using the Django admin you need to create a SocialApp listing your Facebook app credentials. Make sure that this app is attached to the proper site (as in, django.contrib.sites.models.Site).

In your case, there needs to be a django.contrib.sites.models.Site instance with id=2 (check the sites admin) that is listed as a site for the SocialApp.

If either the SocialApp is missing, or if it is created but not attached to a site matching your settings.SITE_ID, then allauth does not know what app to pick, resulting in the error message you listed above.

6
  • 1
    thanks author i was missing django.contrib.sites.models.Site line Mar 15, 2013 at 9:58
  • 10
    I couldn't get the admin panel to show my SITE's id, so I loaded it in a shell: from django.contrib.sites.models import Site and did a Site.objects.all() to see the list. Site.objects.get(id=2) was actually set to example, so I had to change my settings to 3, which was what my localhost was set to. Nov 25, 2015 at 16:00
  • I was getting this error in testing. This gave me a clue to the problem. In your set up you have to add from allauth.utils import get_current_site from allauth.socialaccount.models import SocialApp sa = SocialApp.objects.create(name='Facebook', provider='facebook') sa.sites.add(get_current_site()) Apr 16, 2016 at 13:35
  • 1
    @AdamStarrh, to see the site ID in the admin panel just add admin.site.unregister(Site) and then class SiteAdmin(admin.ModelAdmin): list_display = ('id', 'domain', 'name') and finally admin.site.register(Site, SiteAdmin) to your admin.py file. Feb 9, 2017 at 6:51
  • 2
    I do this: user$ python manage.py shell. Then from within the interactive prompt, I issue the following two commands: >>> from django.contrib.sites.models import Site and then >>> sorted([(site.id,site.name) for site in Site.objects.all()]). The output looks like: [(1, u'www.lvh.me'), (2, u'example.com'), (3, u'www.example.com'), (4, u'example.com:80'), (5, u'www.example.com:80')]
    – NYCeyes
    Oct 3, 2017 at 1:14
19

For me, it showed this error when I had in settings.py:

SITE_ID = 1

It worked when I changed it to 2:

SITE_ID = 2
1
  • For me i changed it to 3 and it worked.
    – JayB
    Apr 26 at 23:18
19

Step 1: Go to your admin page. Find social application

enter image description here

Step 2: now add the lines like the following image. Give your client id and secret key given by google api and move available site (example.com) to chosen sites enter image description here

Step 3: Now go to sites in the side navigation of admin page and customize like the following image and save it

enter image description here

Step 4: now, add, SITE_ID = 1 in settings.py file.

0
18

In my case, on the Add social application page, I forgot to select my site as "Chosen sites" 🤦🏼‍♂️

See screenshot below (on the bottom right is the Chosen Sites list): enter image description here

0
2

As an alternative to putting that into the admin, you can also put it in your settings like so: (At least in 2022 with version django-allauth==0.45.0

SOCIALACCOUNT_PROVIDERS = {
    'discord': {
        # From https://developer.twitter.com
        'APP': {
            'client_id': os.environ['TWITTER_API_KEY'],
            'secret': os.environ['TWITTER_API_SECRET'],
            'key': os.environ['TWITTER_APP_ID'],
        }
    },
    'twitter': {
        # From https://developer.twitter.com
        'APP': {
            'client_id': os.environ['TWITTER_API_KEY'],
            'secret': os.environ['TWITTER_API_SECRET'],
            'key': os.environ['TWITTER_APP_ID'],
        }
    },
}

Documentation is at: https://django-allauth.readthedocs.io/en/latest/installation.html and https://django-allauth.readthedocs.io/en/latest/configuration.html

1

It is possible that Django created an 'example.com' site for you already (if it's not a new project). So if this is the case you will need to delete that entry from the Sites admin page AND change the SITE_ID in settings.py to be the correct ID (probably 2 rather than 1).

Consider playing around with the SITE_ID value. For example: SITE_ID = 3, etc.

1

FWIW, if configuration via the DB is giving you problems, note that you can also use configuration in settings:

SOCIALACCOUNT_PROVIDERS = {
"google": {
    "APP": {
        "client_id": os.environ[("GOOGLE_OAUTH_CLIENT_ID"],
        "secret": os.environ[("GOOGLE_OAUTH_SECRET"],
    },
},
}

@Penners

1
  • You gave multiple answers to the same question. Edit your first answer to incorporate all information. Also note that some hints could be provided as comment.
    – Matthias
    Sep 5, 2022 at 2:03
0

This worked for me

    SOCIALACCOUNT_PROVIDERS = {
    'google': {
        'SCOPE' : [
            'profile',
            'email'
        ],
        'APP': {
            'client_id': os.environ['CLIENT_ID'],
            'secret': os.environ['CLIENT_SECRET'],
        },
        'AUTH_PARAMS': {
            'access_type':'online',
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.