当我尝试使用Django的内置密码重置系统时。它不会考虑我的模板。此外,当我单击重置密码按钮时,它会转到Django管理员重置页面(photo)。
my 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")),
]
答案 0 :(得分:1)
django.contrib.admin
中accounts
INSTALLED_APPS
以上registration/password_reset_form.html
。这意味着将首先找到来自django.contrib.admin
的{{1}},而不是来自accounts
的模板。
您可以将accounts
移到django.contrib.admin
之上,以便Django首先搜索该应用,或者将模板名称重命名为不会发生冲突的内容(例如registration/my_password_reset_form.html
)并更新您的网址使用新模板名称的模式。