在Heroku上运行应用程序后,TemplateDoesNotExist,本地工作正常

y4ekin9u  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(164)

我的应用程序在本地可以很好地与生产设置和数据库配合使用,并且我成功地将应用程序部署到Heroku。

root folder
 env
 src
  app
  fund
  static
  staticfiles
  templates
   includes
    funds_table.html
    pagination.html
   about_me.html
   base.html
   index.html
  user_account
  manage.py
 requirements.txt
 Procfile
 .gitignore

以下是我的模板设置:

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

我检查了os.path.join(BASE_DIR)是否返回了正确的路径-project_root/src。当我在Heroku上打开应用程序时,我收到了错误:

raise TemplateDoesNotExist(", ".join(template_name_list), chain=chain)
 django.template.exceptions.TemplateDoesNotExist: index.html, fund/fund_list.html
 "GET / HTTP/1.1" 500 145 "https://dashboard.heroku.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"

有趣的是,我的应用程序中甚至没有fund/fund_list.html。我试着在Pycharm中使用Search Everywhere,但这个文件不存在,甚至没有在任何地方提到过。我不知道Heroku为什么要找到它。
我做错了什么?

eyh26e7m

eyh26e7m1#

而不是这样:

[os.path.join(BASE_DIR), 'templates'] #You did wrong here. it should not like this

添加以下内容:

[os.path.join(BASE_DIR, 'templates')]

请尝试以上操作并再次上传,看看是否能解决问题。

相关问题