我使用了Django的 auth_views.password_change 来允许用户更改密码。它使用自定义模板并且运行良好,但我遇到的问题是它重定向到Django的密码更改成功管理模板,而不是我声明的自定义模板。 / p>
urls.py
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from . import views
app_name = 'users'
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^add-user/$', views.CreateUserView.as_view(), name='add-user'),
url(r'^search/$', views.UserSearchView.as_view(), name='search-users'),
url(r'^login/$', views.LoginView.as_view(), name='login'),
url(r'^logout/$', views.LogoutView.as_view(), name='logout'),
url(r'^(?P<pk>\d+)/settings/update$', views.UpdateAccountView.as_view(), name='update-account'),
url(r'^settings/change/$', auth_views.password_change, {'template_name': 'users/forms/change-password.html'},
name='change-password'),
url(r'^settings/change-done/$', auth_views.password_change_done,
{'template_name': 'users/forms/change-password-done.html'}, name='change-password-done'),
url(r'^(?P<pk>\d+)/delete-user/$', views.DeleteUserView.as_view(), name='delete-user'),
我想念的任何想法?
答案 0 :(得分:2)
您应该使用:
url(r'^settings/change/$', auth_views.password_change, {'template_name': 'users/forms/change-password.html',post_change_redirect:'change-password-done'},name='change-password'),
在没有post_change_redirect
的情况下,将加载默认模板。
答案 1 :(得分:0)
在INSTALLED_APPS
中,确保在admin
之前指定了包含自定义模板的应用。
Django按顺序搜索模板。
答案 2 :(得分:0)
问这个问题已经很久了,但上面的答案对我没有用,而且确实如此。在//resolve 5*4
//resolve 20+"test"
//resolve c = "20test";
//resolve b = c;
//resolve a = b;
var a = b = c = 5*4+"test";
console.log(a);
console.log(b);
console.log(c);
:
确保此导入存在:
urls.py
然后从网址中删除from django.contrib.auth.views import ..., password_change_done, ...
,并使用您的自定义模板覆盖url(r'^', include('django.contrib.auth.urls'))
视图。同样,我也已在我的代码中实现了上述建议。