6

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?

Shrikant Mavlankar
  • 1,145
  • 1
  • 8
  • 17
Vasile
  • 801
  • 2
  • 13
  • 31

3 Answers3

6

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

Community
  • 1
  • 1
Arun Ghosh
  • 7,634
  • 1
  • 26
  • 38
  • I do have django.contrib.sites in my INSTALLED_APPS. Also, i did makemigrations and migrate. The error is still persisting. – Vasile Jul 14 '16 at 17:56
  • Did you try removing it? And doing makemigration and migrate? – Arun Ghosh Jul 15 '16 at 01:38
  • Yes. First, I tried just to makemigrations and migrate. Than I just removed the database and the migrations and made everything again. – Vasile Jul 15 '16 at 11:08
  • 1
    Is you are using Django allauth then use SITE_ID = 1 in settings.py – Trect Sep 22 '19 at 10:47
2

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()
Trect
  • 2,759
  • 2
  • 30
  • 35
1

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

Piyush Dive
  • 162
  • 1
  • 11