【问题标题】:how can i use path Django for locating and loading templates? Django 3.2我如何使用路径 Django 来定位和加载模板? Django 3.2
【发布时间】:2021-07-21 09:39:51
【问题描述】:

在 django3.2 中,我试图将其用于定位和加载模板? 但不适用于我

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ` [BASE_DIR / 'templates']`,
    }

默认设置是这样的:

`from pathlib import Path`

# Build paths inside the project like this: BASE_DIR / 'subdir'.

BASE_DIR = Path(__file__).resolve().parent.parent 

任何线索可能是什么问题?

【问题讨论】:

    标签: python django templates helper django-3.2


    【解决方案1】:

    如果你想改变你的模板路径,你可以在你的 settings.py 中使用它,例如我在项目的根目录中有一个“模板”目录用于我的模板:

        TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [os.path.join(BASE_DIR, 'templates')],
            'APP_DIRS': True,
        },
    ]
    

    【讨论】:

      【解决方案2】:

      尝试使用

      TEMPLATES = [
          {
              'BACKEND': 'django.template.backends.django.DjangoTemplates',
              'DIRS': [os.path.join(BASE_DIR, 'templates')],
          }
      

      【讨论】:

        猜你喜欢
        • 2011-03-03
        • 2014-09-15
        • 2018-04-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多