[Python] Password reset django-allauth and django-rest-auth

Discussão em 'Python' iniciado por Stack, Maio 12, 2025.

  1. Stack

    Stack Membro Participativo

    I cannot wrap my head around this problem. Read a lot of solutions but cannot seem to find the correct combination that works for me.

    I want to initiate a users password reset flow from within my (android/iOS) app. I think I need django-rest-auth for this to expose an API endpoint something like this:

    from rest_auth.views import PasswordResetView

    urlpatterns = [
    path('password/reset/', PasswordResetView.as_view(), name='rest_password_reset'),
    ]


    Now posting to http://127.0.0.1:8000/password/reset/ with a JSON payload of { "email": "test1@test.com" } gives an error: django.urls.exceptions.NoReverseMatch: Reverse for 'password_reset_confirm' not found.

    Now, I'm struggling with the next part. I found that password_reset_confirm is defined in django.contrib.auth but I do not want to expose the admin-like interface to the user.

    I'd like to use the allauth PasswordResetFromKeyView.

    So, defining password_reset_confirm as:

    path('password/reset/<uidb64>/<token>/',
    PasswordResetFromKeyView.as_view(),
    name='password_reset_confirm'
    ),


    Works. An email is send containing a reset URL. But now, following that URL I'm getting another error: PasswordResetFromKeyView.dispatch() missing 2 required positional arguments: 'uidb36' and 'key'

    Ok, obvious, changed the password_reset_confirm path arguments from <uidb64> and <token> to <uidb36> and <key>. Than the error moves to password_reset_email.html because of the arguments in {{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} Ok, also changed that to uidb32=uid and key=token results in a HTML page displaying "BAD TOKEN".

    Now, I'm completely at a loss. How to configure django-allauth and django-rest-auth so that I can do a rest request to send the email containing a valid URL which the user can use to change his/her password?

    Continue reading...

Compartilhe esta Página