Skip to content
Advertisement

Does PasswordResetConfirmView.py auto populate uid and token?

The view definitely does not populate on my end but password_reset_confirm.html in the demo template folder seems to do that.

password_reset_confirm_form.html

image

urls.py

    path("dj-rest-auth/password/reset/confirm/<str:uid>/<str:token>/",
        # TemplateView.as_view(template_name="password_reset_confirm.html"),
        PasswordResetConfirmView.as_view(),
         name='resend-email-verification'
    ),  

Edit: maybe this webpage here is not the same page in django-rest-auth demo folder.

Advertisement

Answer

Answer credits to GitHub user, riteshbisht.

What I am seeing is UI of browsable API of django rest framework that does not have this functionality for reading url and populating form field unless I tell it to.

For it to do this, I created templates/rest_framework/api.html file and inserted following code inside it:

api.html

{% extends "rest_framework/base.html" %}

{% block style %}
   {{ block.super }}
       <style>
           #btn-link {
               border: none;
               outline: none;
               background: none;
               display: block;
               padding: 3px 20px;
               clear: both;
               font-weight: 400;
               line-height: 1.42857143;
               color: #A30000;
               white-space: nowrap;
               width: 100%;
               text-align: left;
           }
           #btn-link:hover {
               background: #EEEEEE;
               color: #C20000;
           }
       </style>
{% endblock %}

{% block userlinks %}
   {% if user.is_authenticated or response.data.access_token %}
       <li class="dropdown">
           <a href="#" class="dropdown-toggle" data-toggle="dropdown">
               {% firstof user.username 'Registered' %}
               <b class="caret"></b>
           </a>
           <ul class="dropdown-menu dropdown-menu-right">
               {% url 'rest_user_details' as user_url %}
               <li><a href="{{ user_url }}">User</a></li>
               <li>
                   {% url 'rest_logout' as logout_url %}
                   <form action="{{ logout_url }}" method="post">
                       {% csrf_token %}
                       <button type="submit" id="btn-link">Logout</button>
                   </form>
               </li>
           </ul>
       </li>
   {% else %}
       {% url 'rest_login' as login_url %}
       <li><a href="{{ login_url }}">Login</a></li>
       {% url 'rest_register' as register_url %}
       <li><a href="{{ register_url }}">Register</a></li>
   {% endif %}
{% endblock %}


{% block script %}
   {{block.super}}
   <script type="text/javascript">
       var url_elements = window.location.pathname.split('/');
       if (url_elements.length >= 3){
           var uid = url_elements[url_elements.length - 3];
           if (uid !== undefined){
               $('input[name=uid]').val(uid);
           }
           var token = url_elements[url_elements.length - 2];
           if (token !== undefined){
               $('input[name=token]').val(token);
           }
       }
   </script>
{% endblock %}
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement