【问题标题】:How to overwite django password_reset_confirm page?如何覆盖 django password_reset_confirm 页面?
【发布时间】:2018-12-30 17:59:17
【问题描述】:

我是一名新的 Django 开发人员。我正在尝试使用以下 HTML 文件(change_pwd.html)覆盖 django password_reset_confirm.html 页面。

<!DOCTYPE html>
{% load static %}
<html lang="en">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="icon" href="{% static "icon/tab_logo.png"%}">
      <!-- Bootstrap -->
      <link href="{% static "web/vendors/bootstrap/dist/css/bootstrap.min.css" %}" rel="stylesheet">
      <!-- Custom Theme Style -->
      <link href="{% static "web/src/css/login.css" %}" rel="stylesheet">
      <!-- jQuery -->
      <script src="{% static "web/vendors/jquery/dist/jquery.min.js" %}"></script>     
   </head>
   <body >   
      <div class="vertical-center">
         <div class="container">
            <div class="row">
               <div class=" col-md-4 col-md-offset-4">
                  <div id="loginbox" >
                     <h1 class="text-center title">Change Password</h1>
                     </br></br>                          
                     <form id="passwordform" role="form" method="post" action=".">
                        {% csrf_token %}
                        <div style="margin-bottom: 25px" >                          
                           <input type="password" class="pwd" name="new_password1" placeholder="password" autocomplete="off">                                        
                        </div>
                        <div style="margin-bottom: 25px" >
                           <input type="password" class="pwd" name="new_password2" placeholder="repeat password" autocomplete="off">
                        </div>
                        <div style="margin-top:10px" >
                           <!-- Button -->
                           <input id="btn-change-pwd" class="btn btn-primary btn_extend " type="submit" value="Submit">
                        </div>
                     </form>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </body>
</html>

我还覆盖了项目的 Urls.py 如下:

path(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', password_reset_confirm, {'template_name' : 'change_pwd.html'}, name='password_reset_confirm'),

当我重置密码时,页面被重定向到 admin/templates/registration/password_reset_confirm.html 页面,然后显示以下消息:

密码重置链接无效,可能是因为它已被使用。请申请重设新密码。

根据 admin/templates/registration/password_reset_confirm.html,只要 reset_password 链接无效,就会发生此错误。当我从 URL 中删除 {'template_name' : 'change_pwd.html'} 时,它可以工作。但我不知道如何修复 change_pwd.html 中的这个错误。

【问题讨论】:

    标签: html django


    【解决方案1】:

    Django 用户模板必须在注册文件夹中。 例如:模板/注册/change_pwd.html 改变

    path(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', password_reset_confirm, {'template_name' : 'change_pwd.html'}, name='password_reset_confirm'),
    

    path(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', password_reset_confirm, {'template_name' : 'registration/change_pwd.html'}, name='password_reset_confirm'),
    

    【讨论】:

      猜你喜欢
      • 2014-12-17
      • 1970-01-01
      • 2010-10-01
      • 2021-06-16
      • 2014-11-21
      • 1970-01-01
      • 2015-10-06
      • 2012-08-20
      • 1970-01-01
      相关资源
      最近更新 更多