【问题标题】:TemplateDoesNotExist at / on Heroku while working on local server在本地服务器上工作时,Heroku 上的 TemplateDoesNotExist
【发布时间】:2021-08-28 09:18:12
【问题描述】:

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/模板/homepage.html(源不存在)”

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

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

提前感谢您的帮助:)

【问题讨论】:

  • 嗨!该网站是否在本地工作?您可以在引用 html 的位置发布您的 python 视图吗?
  • 您是否在 Heroku 上重新启动了 Django?代码更改后,只有本地开发服务器会自动重启。
  • @sur.la.route,是的,该站点在本地运行。我已经编辑了帖子并添加了 view.py
  • @GwynBleidD,不知道你的意思,但我做了 git init>status> git add -a> git push heroku main >>>> 一切都是最新的;我也应该提交吗?
  • 您可以在运行期间使用logging 或普通文件来保护信息安全 - 然后您可以检查变量中的内容以及提供os.listdir() 的内容以查看磁盘上的内容。跨度>

标签: python django templates heroku


【解决方案1】:

找到原因;

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-28
    • 2016-11-05
    • 2019-10-16
    • 2020-03-16
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多