Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DoesNotExist at /accounts/register/ Site matching query does not exist. (django, python)

Trying again to implement django-registration. When I try to deploy it to the heroku and to register a new user, it gives me a strange error:

Traceback:

#some irrelevant traceback

File "/app/.heroku/python/lib/python2.7/site-packages/registration/views.py" in post
  43.             return self.form_valid(request, form)

File "/app/.heroku/python/lib/python2.7/site-packages/registration/views.py" in form_valid
  91.         new_user = self.register(request, form)

File "/app/.heroku/python/lib/python2.7/site-packages/registration/backends/default/views.py" in register
  86.         site = get_current_site(request)

File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/sites/shortcuts.py" in get_current_site
  15.         return Site.objects.get_current(request)

File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/sites/models.py" in get_current
  67.             return self._get_site_by_request(request)

File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/sites/models.py" in _get_site_by_request
  44.                 SITE_CACHE[host] = self.get(domain__iexact=host)

File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method
  122.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py" in get
  387.                 self.model._meta.object_name

Exception Type: DoesNotExist at /accounts/register/
Exception Value: Site matching query does not exist.

I am following exactly the official documentation.

Where should look for the error? Where is the problem?

like image 304
Vasile Avatar asked Jul 14 '16 17:07

Vasile


3 Answers

If you have django.contrib.sites in your INSTALLED_APPS and you are not having multiple sites, then you have remove it and do a round of makemigration and migrate.

In case you have multiple sites, then ref: Django - Site matching query does not exist

like image 150
Arun Ghosh Avatar answered Nov 07 '22 11:11

Arun Ghosh


Adding from this. This should work

Enter Django shell

$> ./manage.py shell
>>> from django.contrib.sites.models import Site
>>> site = Site()
>>> site.domain = 'example.com'
>>> site.name = 'example.com'
>>> site.save()
like image 32
Trect Avatar answered Nov 07 '22 11:11

Trect


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

like image 1
Piyush Dive Avatar answered Nov 07 '22 13:11

Piyush Dive