将自定义的 django-allauth 模板移动到 'account' 以外的目录

Move customized django-allauth templates to directory other than 'account'

我按照项目文档正确设置了 django-allauth。我想覆盖 django-allauth 模板的外观,所以我转到项目 github 并将 the django-allauth templates folder 下载到我的 accountsapp/templates 目录中。

我的问题是 django-allauth 只会在 templates/account 文件夹中查找它的模板。

我想将我的模板放在 templates/allauth/account 文件夹中,以帮助将我的模板文件与 django-allauth 的模板文件分开。

当我这样做时,django-allauth 无法找到我自定义的模板。

这是我的项目结构:

projectfolder/
    accountsapp/
        templates/

    projectsettings/
        settings.py
    manage.py

我试过的:

  1. 将我的 TEMPLATES 'DIRS' 设置为此

    'DIRS': [ os.path.join(os.path.dirname(BASE_DIR), 'accountsapp', 'templates', 'allauth'), ],
    

    BASE_DIR 是这样的:BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))。 这行得通,但我不确定这是否是解决我的问题的最佳方案practice/solution。

如果您将模板放在 projectfolder/accountsapp/templates/ 中,只要您的模板设置中有 'APP_DIRS': True,应用程序目录加载器就会找到它们。

但是,如果您将模板移动到 projectfolder/accountsapp/templates/allauth 子文件夹中,应用程序目录加载程序将找不到它们,因此您必须将目录添加到 DIRS,就像您已经完成的那样.