Django.contrib.auth Password Reset Token not working


#1

So, the:

{{ protocol }}://localhost:8000{% url ‘django.contrib.auth.views.password_reset_confirm’ uidb64=uid
token=token %} 

Is supposed to return a URL with a ‘random’ string of characters and/or numbers. However mine returns:

Please go to the following page and choose a new password:

http://localhost:8000{% url ‘django.contrib.auth.views.password_reset_confirm’ uidb64=uid

token=token %} 

Your username, in case you’ve forgotten: man

I dont get any errors, I just dont get the correct URL returned to me. My project using before this used the same methods and it worked.


#2

Thanks for making a message here! Sorry again about not responding quickly.

It might be due to my formatting in the book (whoops) — sometimes “curly” apostrophes got added when they should be “straight”. Can you replace the ‘ (around django.contrib…) with ’ and let me know if you still get the error?


#3

Hey, I have been through and re-written the entire piece and I am still getting the same error. I am thinking it might be in the url.py here is my code.

url(r’^accounts/password/reset/(?P[0-9A-Za-z_-]+)/ (?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$’, password_reset_confirm,
{‘template_name’: ‘registration/password_reset_confirm.html’},
name=“password_reset_confirm”),

Here is a screenshot of the code in my project. I had to make it less ‘formatted’ as sublime wouldnt let me use it in the exact why you did.

http://imgur.com/3lCP7hb

and here is the code if I copy and paste it or type it directly into sublime text in your formatting. As you will see I get the ‘pink error lines’

http://imgur.com/uurHpQj

I am really unsure what to do here


#4

In the second example, the content underneath the first line needs to be indented.

There might be an error in my book, maybe the line wrapped improperly and I didn’t notice.

Try this?

The top version has indenting… try that first, and if it doesn’t work, try the below one that has no indents. That way we can make sure indenting isn’t the problem. :)


#5

Discourse is trying to smart display the code, but it’s missing the last bit. Make sure to click on the gist link to see the whole thing. :)


#6

Hey, I tried those neither worked.I was using django reg-redux 1.2 not 1.1 as you have. I reinstalled 1.1 to check if that would fix it, no luck there either.

I am unsure if any of this could be causing trouble?

ACCOUNT_ACTIVATION_DAYS = 7

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
DEFAULT_FROM_EMAIL = '[email protected]'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
EMAIL_PORT = 1025


LOGIN_REDIRECT_URL = "home"

#7

No, none of those should be causing the error.

Can you copy/paste your current urls.py as well as your template code into http://pastebin.com/ for me so I can take a look again?


#8

urls.py

http://pastebin.com/HmiLnwJ9

template

http://pastebin.com/9sMF4SPT


#9

I am also experiencing issues with registering new users. I cannot register new users ever since creating this form
However my login for (using similar html/css as the pastebin file) works fine for users I create in the admin panel.

here is my registration form template.
http://pastebin.com/56Abig6c


#10

I feel terrible about this but it was a simple case of password_rest_email.html and the proper file name password_reset_email.txt. The reset email now works.

However my registration problem is still happening.


#11

Don’t feel terrible, those things happen all the time. :)

Line 36 in your urls.py, your code is not properly indented. See my example again here: https://gist.github.com/limedaring/6001caed0cf253265e0d — the “wrapping” lines need to be indented another layer in. Or change it to one line, as recommended too.


#12

I am still having trouble registering new users, I am really unsure on this one. For some reason login, create post(thing) edit post(thing) work fine, but registering new users does not. When I click ‘submit’ on the register form it just refreshes the page and does not register a new user.

Any ideas?


#13

Did you fix the URLs problem?

As for the register problem, first, make sure your template and url code look exactly like the code in the book. Next, make sure django-registration-redux is installed in your virtual environment, and you’re in the environment. Let me know if you still need help!


#14

One thing I’ve learned from debugging code is that its not always a single problem, sometimes you have multiple things gone wrong. I had two issues that I think caused similar behavior to the original poster’s.

First there was the left and right apostrophe characters that made the password link look like this:

http://localhost:8000{% url ΓÇÿdjango.contrib.auth.views.password_reset_confirmΓÇÖ uidb64=uid token=token %}

As suggested before by the author, I believe that was the book’s formatting. Replacing those 4 ‘smart apostrophe’ characters in password_reset_email.html with plain single quote characters got rid of the broken character encoding, but I still did not get a usable reset link. It showed up like this, on three separate lines:

http://localhost:8000{% url 'django.contrib.auth.views.password_reset_confirm' uidb64=uid token=token %}

That was my clue! The stuff inside of {% and %} is supposed to go to the Python interpreter to run as code. So what I think was happening was that my editor broke up the {% url ‘django …’ %} part and messed up the Python function call that was supposed to generate the random text for the reset link.

Anyway, putting everything from {{ protocol }} through token=token %} on a single line in my text editor finally gave me this:

http://localhost:8000/accounts/password/reset/confirm/NQ/43a-fda06baa91ccfff3484e/

Its really annoying, because indentation matters in Python and various text tools (like Adobe Acrobat) seems to get it wrong frequently. I had a hard time getting exactly what I was seeing into this post without the editor changing things. I hope this helps!
Bob M


#15

Hey Bob, both problems have been resolved. Thanks anyway for your input! :)