首页 > 解决方案 > 在本地服务器上工作时,Heroku 上的 TemplateDoesNotExist

问题描述

Django 和 Heroku 的新手;

加载页面时,我得到“TemplateDoesNotExist at /”。在某处读过它可能与 Caps 有关。

我的模板称为模板。

在 settings.py 中:

from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent 
print(BASE_DIR)
print(BASE_DIR / 'templates')

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [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',
        ],
    },
},

]

这是我的意见.py

from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def homepage_view(request, *args, **kwargs):
print(args)
print(request.user)
return render(request, "homepage.html",{})

然而

在错误中,我得到:“django.template.loaders.filesystem.Loader: /app/ Templates /homepage.html(源不存在)”

即使我得到“一切都是最新的”,Heroku 似乎也没有上传我对 settings.py 所做的更改

每个人似乎都在使用 os.path.join 但我的 Pathlib 工作正常(我假设)。

在此先感谢您的帮助:)

标签: pythondjangotemplatesheroku

解决方案


找到原因;

打开 VS Code 时,我无法提交更改。也许这只是关于第一次提交的事情。

现在无需关闭 VS Code 即可提交。

感谢那些试图提供帮助的人。


推荐阅读