【问题标题】:Move customized django-allauth templates to directory other than 'account'将自定义的 django-allauth 模板移动到“帐户”以外的目录
【发布时间】:2016-12-14 15:17:24
【问题描述】:

我按照项目文档正确设置了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__)))。 这可行,但我不确定这是解决我的问题的最佳做法/解决方案。

【问题讨论】:

    标签: django django-templates django-allauth


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-07-27
      • 2020-08-01
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 2013-09-22
      • 2013-08-11
      • 1970-01-01
      相关资源
      最近更新 更多