html - 显示 django admin 而不是我的 html
问题描述
我正在尝试在 Django 中更改密码。问题是它使用 Django admin 而不是我的 html 模板。如何让我的模板过去,而不是管理员?
urlpatterns = [
path('', index, name='index'),
path('registration/', registration, name='registration'),
path('accounts/', include('django.contrib.auth.urls'), name='login'),
path('accounts/', include('django.contrib.auth.urls'), name='logout'),
path('accounts/password_reset/', PasswordChangeView.as_view(template_name="password_change.html"), name='password_reset'),
]
解决方案
Django 使用第一个匹配的 url 模式。由于您声明了自己的 url 模式来替换其中的一个,django.contrib.auth.urls
因此您应该将其写在这些 url之上。
您还为包含的网址命名,这没有意义。此外,您要替换的模式password_reset
应该使用PasswordResetView
(您编写PasswordChangeView
),我假设您实际上想要替换password_change
。
也无需两次包含相同的 url 模式(django.contrib.auth.urls
无论如何,当您编写一次时,将包含所有 url)。
urlpatterns = [
path('', index, name='index'),
path('registration/', registration, name='registration'),
path('accounts/password_change/', PasswordChangeView.as_view(template_name="password_change.html"), name='password_change'),
path('accounts/', include('django.contrib.auth.urls')),
]
推荐阅读
- python - 如何修复 Seaborn 条形图中的“ValueError:无法解释输入'用户'”错误?
- python - Google 格式的函数摘要未显示在 PyCharm 的快速文档窗口中
- angular - Angular 辅助路由没有为配置的路由之一附加`/`?
- c# - 比较 2 个对象列表,并根据第一个列表中的项目属性创建一个新列表,该列表不存在于 ASP.NET 中
- email - Gmail API - 不发送文本/纯电子邮件作为引用打印
- javascript - React dynamic context menu/submenu
- javascript - 调用scrollTop后,网页总是先上升一点再下降到正确的位置
- android - 使用 AsyncTask 从 Firebase 获取记录?
- matlab - Is there a way to do mpower on a matrix repmat array?
- windows - Windows7下如何在Cygwin中汇编一个64位的汇编语言程序?