2

The password_reset page of my Django site is causing a DoesNotExist exception after an email address is entered and the button pressed.

The four URLs required for the password reset function are in (the main project) urls.py as:

(r'^password_reset/$', 'appname.views.cust_password_reset'),
(r'^password_reset/done/', 'appname.views.cust_password_reset_done'),
(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'appname.views.cust_password_reset_confirm'),
(r'^reset/done/$', 'appname.views.cust_password_reset_complete')

The following is the code used for the associated views:

def cust_password_reset(request):
    return password_reset(request, post_reset_redirect='password_reset/done',template_name='registration/password_reset_done.html')

def cust_password_reset_done(request):
    return password_reset_done(request,  template_name='registration/password_reset_done.html')

def cust_password_reset_confirm(request, uidb36=None, token=None):
    return password_reset_confirm(request, uidb36=uidb36, token=token,
    template_name='registration/password_reset_confirm.html',
    post_reset_redirect='registration/reset/done/')

def cust_password_reset_complete(request):
    return password_reset_complete(request,
    template_name='registration/password_reset_complete.html')

The email address is correctly checked for validity, but the redirect to password_reset/done doesn't appear to happen. The URL stays as password_reset, but causes a DoesNotExist exception with the value 'Site matching query does not exist'.

The URLs and templates seem to work properly and password_reset/done displays correctly when manually accessed.
The templates referenced are exact copies of the original Django templates, with just a header/ footer added. Password Resetting without using custom views/templates results in the same error.

Any ideas as to what could be causing this would be greatly appreciated.

1 Answer 1

2

That error, "Site matching query does not exist" means that the SITE_ID in settings.py does not match up with an actual Site object in the database. Check the id attribute for your site, and make sure it's the same as SITE_ID.

Sign up to request clarification or add additional context in comments.

3 Comments

The SITE_ID in settings.py is 1, and I'm not (purposely at least) changing this anywhere else. In the Settings section of the Request Information shown when the error occurs, the SITE_ID is also 1, but this seems to be coming directly from settings.py. Is it possible that something in the password_reset views could be changing the id automatically?
That error is pretty explicit; there's only one thing that will cause that. Check your database and make sure site_id is 1 there.
It looks like there wasn't a Site object in the database at all - when I added one, it was given id 1 and now the password reset works perfectly - Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.