Home > Mobile >  TemplateDoesNotExist after running app on Heroku, locally works fine
TemplateDoesNotExist after running app on Heroku, locally works fine

Time:11-04

My app works fine locally with production settings and database, and I deployed the app to Heroku successfully. Here is my project structure:

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

Here is my settings for templates:

   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',
            ],
        },
    },
]

I checked that os.path.join(BASE_DIR) returns the right path - project_root/src. When I open the app on Heroku, I receive the error:

 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"

What is interesting, I don't even have the fund/fund_list.html in my app. I tried to use Search Everywhere in Pycharm, and this file doesn't exist and even hasn't been mentioned anywhere. I'm not sure why Heroku tries to find it.

What I'm doing wrong?

CodePudding user response:

instead of this:

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

add this:

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

Try above And upload again and see if this is solves

  • Related