본문 바로가기
프레임워크/Django

[allauth] admin 페이지 접속시 오류

by nahkim 2023. 5. 24.

이슈 내용


admin페이지 접속시 이상한 페이지로 리다이렉션 되며 Site matching query does not exist 에러 발생

File "venv/lib/python3.9/site-packages/django/db/models/query.py", line 435, in get
    raise self.model.DoesNotExist(
django.contrib.sites.models.Site.DoesNotExist: Site matching query does not exist.
[29/Nov/2022 11:51:20] "GET /admin/login/?next=/admin/ HTTP/1.1" 500 150660

해결 방법


admin에서 example.com 사이트를 삭제해서 난 오류였다.

 

 

방법 1-1

example.com 다시 추가해준다.

$> ./manage.py shell
>>> from django.contrib.sites.models import Site
>>> site = Site()
>>> site.domain = 'example.com'
>>> site.name = 'example.com'
>>> site.save()

1-2 root settings.py에 SITE_ID = 1 추가

# root settings.py에 추가

SITE_ID = 1

 

방법 2-1

$> ./manage.py shell
>>> from django.contrib.sites.models import Site
>>> site = Site.objects.create(domain='example.com', name='example.com')
>>> site.save()

2-2 root settings.py에 SITE_ID = 1 로 변경

# root settings.py에 추가

SITE_ID = 1

 

 

참고 자료


https://stackoverflow.com/questions/16068518/django-site-matching-query-does-not-exist

 

Django - Site matching query does not exist

Im trying to get the admin site of my app in Django working. Ive just sync`d the DB and then gone to the site but I get the error ... Site matching query does not exist. Any ideas ?

stackoverflow.com