【问题标题】:Heroku Django cant find templateHeroku Django 找不到模板
【发布时间】:2021-04-12 16:16:00
【问题描述】:

尽管我有 'DIRS': [os.path.join(BASE_DIR, 'templates')],但在我的设置中,Heroku 仍然找不到模板。顺便说一句,Heroku 找到了一些模板,但似乎他无法在 CBV 上找到这些模板。知道我可能有什么问题吗?提前谢谢你。

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        # 'DIRS': [BASE_DIR / 'templates'],
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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',
            ],
        },
    },
]

【问题讨论】:

    标签: django heroku


    【解决方案1】:

    我发现了问题。

    class InventoryView(MyLoginRequiredMixin,ListView):
        template_name = 'inventory/RawMaterials.html'
        model = RawMaterial
    

    尽管模板文件夹名为 Inventory,但此文件仍在本地计算机上运行

    所以我将 CBV 中的模板更改为

    class InventoryView(MyLoginRequiredMixin,ListView):
        template_name = 'Inventory/RawMaterials.html'
        model = RawMaterial
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-23
      • 2018-06-26
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 2018-01-02
      • 2012-07-10
      相关资源
      最近更新 更多