1

Expecting to be able to access django admin panel and add social accouunt

opening admin panel by adding standard admin/ extension to local preview port URL. This is expected to lead to classic django admin panel.

going to the admin url instead leads to an error message

the website is otherwise displaying fine.

A simple google oath signin is currently being implemented.

Error message:

DoesNotExist at /admin/login/
Site matching query does not exist.
Request Method: GET
Request URL:    http://8000-lmcrean-project4-avaw7dd1zq8.ws-eu106.gitpod.io/admin/login/?next=/admin/
Django Version: 3.2.23
Exception Type: DoesNotExist
Exception Value:    
Site matching query does not exist.
Exception Location: /workspace/.pip-modules/lib/python3.9/site-packages/django/db/models/query.py, line 435, in get
Python Executable:  /home/gitpod/.pyenv/versions/3.9.17/bin/python3
Python Version: 3.9.17
Python Path:    
['/workspace/Project-4',
 '/home/gitpod/.pyenv/versions/3.9.17/lib/python39.zip',
 '/home/gitpod/.pyenv/versions/3.9.17/lib/python3.9',
 '/home/gitpod/.pyenv/versions/3.9.17/lib/python3.9/lib-dynload',
 '/workspace/.pip-modules/lib/python3.9/site-packages',
 '/home/gitpod/.pyenv/versions/3.9.17/lib/python3.9/site-packages']
Server time:    Sat, 11 Nov 2023 15:17:58 +0000

traceback details in full

Currently trying to fix with this tutorial

“Set up Google Sign-in for Faster Django Login Experience Feat. Tech with Tim.” Akamai DevRel, YouTube Video, 12 Dec. 2022, https://youtu.be/yO6PP0vEOMc?feature=shared&t=1328. Accessed 11 Nov. 2023.

  • have followed correctly with all working up to 22 minutes in
  • migration was recently made after setting up urls, views and templates for google oauth as per the tutorial, there were no obvious issues with this
  • before that django-admin panel seemed to be working fine

settings.py and url are likely problem areas

installed apps seems ok on settings.py - can be viewed here in full

this was recently implemented but is correct according to tutorial:

AUTHENTICATION_BACKENDS = (
    "django.contrib.auth.backends.ModelBackend",
    "allauth.account.auth_backends.AuthenticationBackend"
)

urlpatterns in urls.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path("", include("blog.urls"), name="blog-urls"),
    path('summernote/', include('django_summernote.urls')),
    path("accounts/", include("allauth.urls")),
    path("", include("users.urls"))
]

1 Answer 1

1

The error message "Site matching query does not exist," typically occurs in Django when the SITE_ID setting in settings.py refers to a Site object that does not exist in the database.

I managed to debug this with the Python Shell by checking existing site ID.

from django.contrib.sites.models import Site
existing_site = Site.objects.get(domain='http://127.0.0.1:8000')
print(existing_site.id)

The returning statement revealed that the SITE_ID should be 2, not 1 as previously set.

This was fixed with an update to settings.py to match the correct site ID:

SITE_ID = 2

The django admin panel can now be accessed without any further errors.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.