3
votes

I'm new in Django and really confused.

I'm developing a authentication API by using built in rest auth.

I want to reset password by API view but the mail link I send redirect me to "password reset confirm" HTML template but I need to redirect this link to API view.

I expect to redirect to this page:

enter image description here

but my email link redirect to this HTML template page:

enter image description here

this email is send by password_reset_email.html

someone asked for password reset for email {{ email }}. Follow the link below:
{{protocol}}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}

this is the url for redirecting this email link:

path('password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)/(?P<token>.+)/$', auth_views.PasswordResetConfirmView, name='password_reset_confirm'),
1

1 Answers

0
votes

It's your Url:

path('password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)/(?P<token>.+)/$', auth_views.PasswordResetConfirmView, name='password_reset_confirm'),

And you didn't specify your template file. That's why it's take Django default template and it's show Django admin password reset page.

Update your URL. And specify your custom template name.

urls.py

path('password-reset-confirm/<uidb64>/<token>',auth_views.PasswordResetConfirmView.as_view(template_name='users/password_reset_confirm.html'), name='password_reset_confirm'),

Here is my Custom Template. And update your template from the Django rest framework doc.

password_reset_confirm.html

{% extends "users/users_base.html" %}
{% load crispy_forms_tags %}
{% load static %}

{% block content %}
<!-- Nested Row within Card Body -->

    <form class="user" method="POST">
        {% csrf_token %}
        <div class="form-group mb-6">
             {{ form | crispy }}
        </div>
        <div class="form-group text-center ">
            <button type="submit" class="btn btn-primary btn-user text-center">
                Change Password
            </button>
        </div>
    </form>

{% endblock %}