使用 django 身份验证重置密码

reseting the password using django authentication

当我尝试使用 Django 的内置密码重置系统时。它没有考虑我的模板。此外,当我单击重置密码按钮时,它会将我带到 Django 管理员重置页面 (photo)。

我的the file map

我的urls.py:-

from django.conf.urls import url
from django.contrib.auth import views as auth_views
from . import views

app_name = 'accounts'

urlpatterns = [
    url(r"^login/$", auth_views.LoginView.as_view(template_name = "accounts/login.html"),name='login'),
    url(r"^logout/$", auth_views.LogoutView.as_view(template_name='thanks.html'), name="logout"),
    url(r"^signup/$", views.SignUpView, name="signup"),
    url(r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',views.activate, name='activate'),
    url(r'^password_reset/$', auth_views.PasswordResetView.as_view(template_name='registration/password_reset_form.html'), name='password_reset'),
    url(r'^password_reset/done/$', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
    url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
    url(r'^reset/done/$', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
]

模板:-

password_reset_form.html

  {% extends 'reg_base.html' %}
{% load bootstrap3 %}

{% block body_block %}
  <h3 class="display-1">Forgot password</h3>
  <form method="POST">
    {% csrf_token %}
    {% bootstrap_form form %}
    <button class="btn btn-primary" type="submit">Submit</button>
  </form>
{% endblock %}

password_reset_confirm.html

{% extends 'reg_base.html' %}
{% load bootstrap3 %}
{% block body_block %}
  {% if validlink %}
    <h3 class="display-2 text-center">Change password</h3>
    <form class="form-control" method="post">
      {% csrf_token %}
      {% bootstrap_form form %}
      <button class="btn btn-default" type="submit">Change password</button>
    </form>
  {% else %}
    <p class="lead">
      The password reset link was invalid, possibly because it has already been used.
      Please request a new password reset.
    </p>
  {% endif %}
{% endblock %}

已安装的应用程序

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'bootstrap3',
    'accounts',
]

主要Urls.py

from django.conf.urls import url, include
from django.contrib import admin
from . import views


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$',views.HomepageView.as_view(),name='home'),
    url(r'^accounts/', include("accounts.urls")),
    url(r'^accounts/', include("django.contrib.auth.urls")),
]

您的 INSTALLED_APPSaccounts 以上 django.contrib.admin。这意味着 django.contrib.admin 中的 registration/password_reset_form.html 将首先被找到并使用,而不是 accounts 中的模板。

您可以将 accounts 移动到 django.contrib.admin 上方,以便 Django 首先搜索该应用程序,或者将模板名称重命名为不冲突的名称(例如 registration/my_password_reset_form.html)并更新使用新模板名称的 URL 模式。