PasswordResetConfirmView.py 是否自动填充 uid 和令牌?

Does PasswordResetConfirmView.py auto populate uid and token?

我这边肯定不会填充该视图,但演示模板文件夹中的 password_reset_confirm.html 似乎会填充该视图。

password_reset_confirm_form.html

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'
    ),  

编辑:这里的网页可能与 django-rest-auth 演示文件夹中的网页不同。

在django中,它被定义为(在django代码中):

urls.py

path('reset/<uidb64>/<token>/',views.PasswordResetConfirmView.as_view(),name='password_reset_confirm'),
path('reset/done/',views.PasswordResetCompleteView.as_view(),name='password_reset_complete')

然后,您可以根据需要进行自定义,并通过在您自己的views.py文件中继承来覆盖它。

Answer credits to GitHub user, riteshbisht.

我看到的是 UI 的可浏览 API 的 django rest 框架,它没有读取 url 和填充表单字段的功能,除非我告诉它。

为此,我创建了 templates/rest_framework/api.html 文件并在其中插入了以下代码:

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 %}