Django – Site matching query does not exist

Question:

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 ?

Asked By: felix001

||

Answers:

Every django app needs a Site to run. Here you do not seem to have it.

Log into your django shell

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

or

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

You should be all set.

Answered By: karthikr

You also need to make sure that the site domain is the same with the one you actually use. For example if you are you are accessing the admin site from http://127.0.0.1:8000/admin/ then your site.domain should be: site.domain = ‘127.0.0.1:8000’.

Answered By: Evangelos Tolias

Add django.contrib.sites in django INSTALLED_APPS and
also add SITE_ID=1 in your django setting file.

Answered By: Mr Singh

Adding SITE_ID=1 on settings.py did the trick for me.

Try out this in settings.py:

SITE_ID = 1

I’m using wsgi, so I had to reboot twice, not sure why.

then clear cache and that was it.

Answered By: Brian Sanchez

SITE_ID = 1 i didn’t work for me

I had to go to the python shell
./manage.py shell

Then get the existing site id using name or domain

from django.contrib.sites.models import Site
Site.objects.get(name='back').id
> 6

For me it was 6, all i had to do then is to change the SITE_ID = 6 and it worked fine

Answered By: Ameur Baccoucha
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.