Search code examples
pythondjangoherokudjango-registration

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?


Solution

  • 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