5

I was working on my project for a while and recently noticed that when i try to go to localhost/admin/ it gives out an error :

DoesNotExist at /admin/

Site matching query does not exist.

Request Method:     GET
Request URL:    http://127.0.0.1:8000/admin/
Django Version:     1.3
Exception Type:     DoesNotExist
Exception Value:    

Site matching query does not exist.

Exception Location:     C:\Python27\lib\site-packages\django\db\models\query.py in get, line 349

Usually when i go there it makes me login first and then redirects me, but now it just errors unless i am already logged in

I can only enter my admin after login in as admin in the localhost login functionality i created for users and then going to that page. Also the logout from the admin page stoped working giving the same error.

I was working on adding a new field to the user module and displaying new user creation form when this happened.

anyone had similar problem? Or maybe someone knows what causing this?

Angie
  • 313
  • 1
  • 8
  • 20

4 Answers4

11

Check out this thread, it seems relevant.

From the last post:

Since the exception said " 'Site' matching query does not exist", and the docs said something about the SITE_ID describing the site in the django_site database table, I went ahead and took a look at my (sqlite) database. The django_site table was empty, so I added a row with id==1 (the same that I have in settings.py) and then it worked.

If you don't mind loosing your data, you can try to run 'sql appname', as this table was supposed to be built automatically.

Dominik
  • 377
  • 4
  • 11
  • Actually yeah! That was the problem. I made a different Site ID because I wanted site information sent to user when he resets his password. So for some reason when Site_id = 2 it doesnt work but site_id = 1 does! Thank you :) – Angie Aug 08 '11 at 08:37
  • 4
    In case others run into this, I got the same error after deleting "example.com" from the sites list. It took awhile to find the source because my login session was still active. Commenting out django.contrib.sites in INSTALLED_APPS solved this. – Joe Mornin Mar 30 '12 at 13:09
  • @JosephMornin I also got this issue because of deleting example.com. Another solution however (if you need to keep the sits app) is to open a Django shell and make a new site and save it, then change the SITE_ID in settings.py to be the id of the site you just created. This way you can still use the sites app if you need to. – floer32 Aug 25 '12 at 22:36
9

Try commenting or deleting 'django.contrib.sites' from the INSTALLED_APPS setting on your settings.py, that should solve the problem.

You can also check your sites table:

python manage.py shell
from django.contrib.sites.models import Site
Site.objects.all()

And if there is no site defined for localhost, you can create it or re-create it:

Site.objects.create(pk=1, domain='127.0.0.1:8000', name='localhost')

That worked for me.

iferminm
  • 2,019
  • 19
  • 34
1

For anyone trying to install django-allauth for django 1.8 or above and getting this error after following the instructions here:

http://django-allauth.readthedocs.org/en/latest/installation.html

Just add the following line to urls.py:

from django.contrib.sites.models import Site

Hope this saves someone time.

Andrés Pérez-Albela H.
  • 4,003
  • 1
  • 18
  • 29
Ken T.
  • 11
  • 2
0

INSTALLED_APPS = [ .... 'django.contrib.sites', 'allauth', 'allauth.account', 'allauth.socialaccount', ....bla bla bla ] SITE_ID = 1

try add SITE_ID=1 ..it worked for me

Batuhan
  • 1,521
  • 12
  • 29