如何覆盖所有 Auth 内置模板 Django

问题描述 投票:0回答:3

我正在使用 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
3个回答
2
投票

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

在这里,您想要覆盖密码重置页面,然后在项目中创建“password_reset.html”模板。您的模板目录结构必须类似于

yourproject/templates/allauth/account/
。我希望这对你有帮助:)


0
投票

我最近在 django-allauth 0.58.1 上苦苦挣扎,最后我发现了它是如何工作的(这确实是一段漂亮的代码,绕过它会很遗憾),所以...

只需创建与 django-allauth 类似的模板路径,并将它们放在主“模板”目录中。您可以在 allauth 的 github

上找到所有模板

快速简单的定制可以是:

  • templates/allauth/layouts/base.html
    中重定向到您自己的base.html(或将其用作您自己的基础):
{% extends 'my_base.html' %}
  • 确保
    {% load socialaccount %}
    位于您自己的base.html的顶部
  • 自定义templates/allauth/elements/中的所有元素(比看起来更快)

allauth 的 github 示例中你会发现一些准备好的模板,我强烈建议复制/粘贴(然后自定义)至少这 2 个:

  • allauth/elements/fields.html
  • allauth/elements/field.html

我希望这对我自己应该有帮助。


0
投票

正确

模板/帐户/

模板/openid/

模板/社交帐户/

© www.soinside.com 2019 - 2024. All rights reserved.