【问题标题】:Template Not Found ( path is set the setting.py Templates )未找到模板(路径设置为 setting.py 模板)
【发布时间】:2020-11-10 23:23:35
【问题描述】:

嘿,我是 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)

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

【问题讨论】:

    标签: python html django templates heroku


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      原来使用 \ 是我切换到 / 的问题,如果您知道为什么,请注意解释它会让我很开心。

      【讨论】:

      • 看起来 Heroku 正在 Linux 上运行,路径分隔符为 /。大概就是这个原因。您可以使用os.path.sepos.path.join() 来支持Windows Linux。
      猜你喜欢
      • 2016-06-18
      • 2011-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-25
      • 1970-01-01
      相关资源
      最近更新 更多