首页 > 解决方案 > 未找到模板(路径设置为 setting.py 模板)

问题描述

嘿,我是 Django 的新手,我的第一个项目几乎完成了,但是当我heroku open在终端中使用 Heroku 打开我的网站时遇到问题,当网站打开时,我收到一个错误,提示我的基本模板丢失。

设置

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

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

任何 html

{% extends "learning_logs\base.html" %}

 .........

错误

TemplateDoesNotExist at /
learning_logs\base.html

django.template.loaders.filesystem.Loader: /app/templates/learning_logs\base.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/learning_logs/templates/learning_logs\base.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/users/templates/learning_logs\base.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.7/site-packages/bootstrap4/templates/learning_logs\base.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.7/site-packages/django/contrib/admin/templates/learning_logs\base.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.7/site-packages/django/contrib/auth/templates/learning_logs\base.html (Source does not exist)

如果任何其他代码可能有帮助,请告诉我。

标签: pythonhtmldjangotemplatesheroku

解决方案


还不能评论,所以我会在回复中提到:

Windows 系统使用反斜杠“\”来表示文件夹/目录的变化,而其他系统使用正斜杠“/”。Heroku 有 linux 服务器,无法识别正斜杠


推荐阅读