0

from tests.py

url = reverse('password_change_done', args =[self.mylog.token, self.john.password])

from urls.py

url(r'^password_change_done/$', password_change_done, name='password_change_done'),

from views.py

def password_change_done(request, token=None, new_pass=None):
print(request.method)
if request.method =="POST":
    try:
        login_obj = LoginLog.objects.get(token=token)
        trust = login_obj.trust_obj.name
        new_pass = login_obj.login_obj.password
        new_pass = request.POST.get("new_pass")

        login_obj.login_obj.password = new_pass
        login_obj.login_obj.save()

        return render(request, 'password_change_done.html', {
            "Trust": request.POST.get("Trust"),
            "email": request.POST.get("email"),

        })

from password_change_done.html

{% extends 'base.html' %}
{% block body %}
<h2>The password for {{Trust}}, {{email}} has been updated.</h2>
<br><br>
You can now close this window.
{% endblock %}

I have this error:

django.urls.exceptions.NoReverseMatch: Reverse for 'password_change_done' with arguments '('cc6f98fe-93ea-4cc2-97c5-a8b16b6308cc', 'pbkdf2_sha256$30000$zdbekeYMwQfC$WyW7FsZZg6hgWhmw6USs6etLVJlOnol6RmISFSlg1+4=')' and keyword arguments '{}' not found. 1 pattern(s) tried: ['password_change_done/$']

I thought that the pattern reverse has used matches correctly so why am I getting this error?

2 Answers2

0

Your URL pattern does not have any groups:

url(r'^password_change_done/$', password_change_done, name='password_change_done'),

Therefore you should reverse it without any arguments:

url = reverse('password_change_done')

Since the password_change_done view simply displays a message that the password has been changed, no arguments are required.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • What do you mean a group? My function does require arguments as it displays the changes on password_change_done.html –  Oct 29 '18 at 16:42
0

The url password_change_done/ doesn't need any additional argument. You can reverse it like this:

url = reverse('password_change_done')

For a reverse of this kind:

url = reverse('password_change_done', args=[self.mylog.token, self.john.password])

the corresponding url pattern would looks like:

url(r'^password_change_done/(?P<token>.+)/(?P<b64pwd>.+)/$', password_change_done, name='password_change_done'),
Antwane
  • 20,760
  • 7
  • 51
  • 84
  • Feel free to accept the answer that helped you to solve your issue. That's also true for [your old](https://stackoverflow.com/a/52190169/1887976) [SO questions](https://stackoverflow.com/a/51783393/1887976). – Antwane Oct 29 '18 at 16:48