Site Matching Query Does Not Exist

Site matching query does not exist

If you don't have a site defined in your database and django wants to reference it, you will need to create one.

From a python manage.py shell :

from django.contrib.sites.models import Site
new_site = Site.objects.create(domain='foo.com', name='foo.com')
print (new_site.id)

Now set that site ID in your settings.py to SITE_ID

Django error - matching query does not exist

your line raising the error is here:

comment = Comment.objects.get(pk=comment_id)

you try to access a non-existing comment.

from django.shortcuts import get_object_or_404

comment = get_object_or_404(Comment, pk=comment_id)

Instead of having an error on your server, your user will get a 404 meaning that he tries to access a non existing resource.

Ok up to here I suppose you are aware of this.

Some users (and I'm part of them) let tabs running for long time, if users are authorized to delete data, it may happens. A 404 error may be a better error to handle a deleted resource error than sending an email to the admin.

Other users go to addresses from their history, (same if data have been deleted since it may happens).

Django - Site matching query does not exist

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.

Django site matching query does not exist error

i just made this :
in settings.py:
i added

INSTALLED_APPS =[
'django.contrib.sites']

then :

SITE_ID=1

Site matching query does not exist. Everything is set, site domain defined

So the problem was that i deleted the "example.com" instance instead of modifying it and created a new one. To solve the problem delete your instance again and create a new one with id=1. Site.objects.create(id=1, name='example.com', domain='example.com')

Getting Site Matching Query Does Not Exist Error after creating django admin

The Site object for your Django project is missing. Each Django project has a Site object which contains the site's name and domain. It is usually automatically created when creating a Django project (in particular, when the syncdb command runs) but in your case it seems that didn't happen.

To fix it:

Open the Django shell for your site (python manage.py shell).

Type the following:

>>> from django.contrib.sites.models import Site
>>> Site.objects.create(name='example.com', domain='example.com')

If you want to change these values later, go to your admin panel (/admin/) and edit the site object in the section Sites.

Django : matching query does not exist on save() method

The problem was my processing order. As POI is a child of Topology, I can't create a POI object and link it to a POI object created afterwards. As I switch my app from SQLAlchemy, the logic for this kind of things is different.



Related Topics



Leave a reply



Submit