【问题标题】:Change django templates path更改 django 模板路径
【发布时间】:2016-07-31 04:35:23
【问题描述】:

我正在使用 django-registration-redux 并想更改模板的样式。为此,我从 github 获取模板/注册文件夹,并使用模板添加到我的文件夹中。如何告诉我的项目文件夹中的 django 搜索模板

D:\django\blogRodion\blogRodion\blog\templates\registration\

而不是

 D:\django\blogRodion\blogRodion\env\lib\site-packages\registration\templates\registration\

【问题讨论】:

  • 你能把你的registration放在django.contrib.admin上面吗?

标签: django


【解决方案1】:

在你的 settings.py Django (1.8+) 中添加以下代码

import os

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

TEMPLATES = [
   {
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [
        os.path.join(BASE_DIR, 'templates'),
        'other_dir_path_to_include'
    ],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
        ],
    },
  },
]

更多详情请见:https://docs.djangoproject.com/en/1.9/ref/settings/#std:setting-TEMPLATE_DIRS

【讨论】:

  • 这对我不起作用。我只是覆盖源文件夹。
  • 在项目的根目录创建一个名为“templates”的文件夹,并将您的模板保存在其中。它会起作用的。
  • 这项工作:'DIRS': [ os.path.join(BASE_DIR, 'blog\\templates'), ],
猜你喜欢
  • 2013-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-08
  • 1970-01-01
  • 2016-04-06
  • 2020-12-05
  • 2012-08-21
相关资源
最近更新 更多