My django project is working with a third-party forum. The activation_email is being send through get_current_site(request)
.
The password rest is done by a django built called password_reset
from django.contrib.auth.views import
.
For another app I needed to install django.contrib.sites
. Through that get_current_site(request)
does not give me the current site, but "example.com" from django.contrib.sites.models
. The problem is:
My project is online already. So I thought I can delete example.com and add my domain-name. But now I can not sign in anymore and this error occurs:
django.contrib.sites.models.DoesNotExist: Site matching query does not exist.
Your Django project looks for a entry in the Site model but can't find it. Therefore Django raises an DoesNotExist error.
What you can do to untwist this is recreate the deleted Site object. It doesn't need to be called example.com
, use the appropriate domain name.
If you locked yourself out. You can always create a shell session. SSH to your server and in the folder with manage.py type:
$ python manage.py shell
>>> from django.contrib.sites.models import Site
>>> site = Site(domain="yourdomain.com", name="My awesome site")
>>> site.save()
Other model entries can have references to the old site object. Normally the primary key (id) of the first Site object is 1. But your newly created site object has some other id. Most of the time you do not want to change id's because it will break relations. But we try to restore broken relations so here we go:
>>> print(site.id)
2 # The id of the current site object.
>>> site.id = 1
>>> site.save()
>>> print(site.id)
1
Or just open a db session and create this object with SQL statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With