【问题标题】:How to override All Auth built-in templates Django如何覆盖所有 Auth 内置模板 Django
【发布时间】:2020-06-10 05:30:46
【问题描述】:

我正在使用 Django all auth 来实现密码重置功能,但我想自定义密码重置模板,下面是我的网址:

urls.py

from django.conf.urls import url,include
from django.urls import path
from rest_framework_jwt.views import obtain_jwt_token,refresh_jwt_token
from . import views


# Registration,Login,Forgot,Profile change

urlpatterns=[

    url(r'^accounts/', include('allauth.urls')),

]

当我点击这个网址时->http://127.0.0.1:8000/ThiefApp/accounts/password/reset/

我得到了下面的模板

如何自定义上述模板或如何使用不同的模板。有什么建议吗?

【问题讨论】:

    标签: python django django-templates django-allauth


    【解决方案1】:

    allauth 在 allauth/templates 目录中包含许多模板。如果你想覆盖任何模板,那么你需要在你的项目中添加同名的模板,allauth 模板目录包含。(参考:https://django-allauth.readthedocs.io/en/latest/templates.html#overridable-templates)。

    在这里您要覆盖密码重置页面,然后在您的项目中创建一个 "password_reset.html" 模板。您的模板目录结构必须类似于yourproject/templates/allauth/account/。我希望这会对你有所帮助:)

    【讨论】:

    • 嗯,我已经创建了模板,但仍然得到以前的模板,
    • @NabeelAyub 更新答案中给出的模板目录路径。
    • 谢谢,你能告诉我覆盖accounts/password/reset/done/,accounts/password/reset/key/4-set-password/和ThiefApp/的模板名称是什么吗帐户/密码/重置/密钥/完成/。
    • 您可以在allauth/account/文件夹中找到所有模板。在这里,您可以轻松地从模板名称中了解要使用的模板。
    猜你喜欢
    • 2020-02-18
    • 2018-05-16
    • 2011-12-07
    • 2011-07-21
    • 2017-07-06
    • 2015-04-15
    • 2018-10-16
    • 2013-09-18
    • 2015-03-16
    相关资源
    最近更新 更多