更改 URL 覆盖的模板

Change URL Of Overridden Templates

在我的网站 user 上,通过以下地址访问他们的帐户:

http://127.0.0.1:8000/users_area/username/profile

在那里他们会找到一个按钮 'change password'(一个覆盖的 django 模板),它将把他们带到:

http://127.0.0.1:8000/accounts/password/change/

它非常小,我可能太挑剔了,但是否可以保留这个被覆盖的模板但更改它的 url?相反,我希望 change password url 是这样的:

http://127.0.0.1:8000/users_area/username/password/change/

我尝试在用户的应用程序中创建一个模板,将 'change password' 模板内容复制到其中,然后链接到它而不是覆盖的 'change password' 模板,但是(显然,在事后看来)它不起作用。


我将作为旁注添加。我实际上有两种用户类型,userspowerusers。每个人都有一个独特且截然不同的 'users_area':

http://127.0.0.1:8000/users_area/username/profile

http://127.0.0.1:8000/powerusers_area/username/profile

如果我得到上述问题的答案,我实际上希望将它应用到我的两种不同的用户类型(应该不难,但我认为我应该提到它)。

谢谢。

你可以这样做 urls.py

from django.contrib.auth import views as auth_views
urlpatterns = i18n_patterns(
    # other URLS
    path('/users_area/username/password/change/', auth_views.PasswordChangeView.as_view, name='change_password'),
    # more URLS from auth?
)

如果你想定制它们,即使有一个定制的用户模型,你仍然可以像这样从 Django 中重用很多东西

    # authentication
    path('user_register', user_register_view, name='user_register'),
    path('login', login_view, name='login'),
    path('logout', logout_view, name='logout'),
    path('change_password', change_password_view, name='change_password'),
    path('reset_password/',
         auth_views.PasswordResetView.as_view(template_name="MyUser/password_reset.html"),
         name="reset_password"),
    path('reset_password_sent/',
         auth_views.PasswordResetDoneView.as_view(template_name="MyUser/password_reset_sent.html"),
         name="password_reset_done"),
    path('reset/<uidb64>/<token>/',
         auth_views.PasswordResetConfirmView.as_view(template_name="MyUser/password_reset_form.html"),
         name="password_reset_confirm"),
    path('reset_password_complete/',
         auth_views.PasswordResetCompleteView.as_view(template_name="MyUser/password_reset_done.html"),
         name="password_reset_complete"),
    path('profile/<username>', profile_view, name='profile'),