0

After reading through this question, I have some insight as to why when trying to launch my app after deploying to Heroku, I get the following error: raise TemplateNotFound(template), jinja2.exceptions.TemplateNotFound: index.html.

They are saying that the templates should be at the project directory root as shown here. Is there anyway I can modify where Heroku is trying to look for the templates directory? I modified my project structure since my app was growing in size and starting to look a bit unorganized.

Here is a look at my current project structure:

Project
│
├── App
│   ├── DbMs
│   │   ├── db_actions.py
│   │   └── user_operations.py
│   ├── UI
│   │   ├── static
│   │   │   ├── css
│   │   │   │   └── main.css
│   │   │   ├── fonts
│   │   │   │   └── Gotham_Medium_Regular.json
│   │   │   ├── images
│   │   │   │   ├── favicons
│   │   │   │   │   ├── android-chrome-192x192.png
│   │   │   │   │   ├── android-chrome-512x512.png
│   │   │   │   │   ├── apple-touch-icon.png
│   │   │   │   │   ├── favicon-16x16.png
│   │   │   │   │   ├── favicon-32x32.png
│   │   │   │   │   ├── favicon.ico
│   │   │   │   │   └── site.webmanifest
│   │   │   │   ├── header.jpeg
│   │   │   │   ├── logo.png
│   │   │   │   └── radar-chart.png
│   │   │   └── javascript
│   │   │       ├── FontLoader.js
│   │   │       ├── TextGeometry.js
│   │   │       ├── create.js
│   │   │       ├── exploreMusic.js
│   │   │       └── tracks.js
│   │   └── templates
│   │       ├── base.html
│   │       ├── create.html
│   │       ├── index.html
│   │       ├── information.html
│   │       └── tracks.html
│   ├── __init__.py
│   ├── authenticate.py
│   ├── routes.py
│   ├── services.py
│   └── templates
├── Pipfile
├── Procfile
├── README.md
├── Testing
│   ├── __init__.py
│   └── testing.py
├── __pycache__
│   ├── authenticate.cpython-39.pyc
│   ├── config.cpython-39.pyc
│   ├── main.cpython-39.pyc
│   ├── services.cpython-39.pyc
│   └── user_operations.cpython-39.pyc
├── config.py
├── package-lock.json
├── package.json
├── requirements.txt
├── run.py
└── setup.py

For more context, I have everything running perfectly fine locally, I only see this error after deployment. Thanks to anyone who can provide insight.

EDIT: I tried moving the templates folder into the App directory as well as the project root and changing the following line in __init__.py both times:

template_dir = os.path.abspath('../Project/templates/')

After deploying each time, I changed the location of templates, still see the same error from Heroku: raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: index.html

wisenickel
  • 346
  • 4
  • 16

1 Answers1

0

So it turns out that Heroku is picky with modifying the location of the templates & static folders.

Whats was very misleading about this issue was that I could run everything fine locally but as soon as I deployed to Heroku, the entire App would break..

The way I fixed this was by moving templates & static into the App directory. I also had to make sure that i changed the following line from:

template_dir = os.path.abspath('../Soulify/App/templates/')
static_dir = os.path.abspath('../Soulify/App/UI/static/')
app = Flask(__name__, template_folder=template_dir, static_folder=static_dir)

to:

app = Flask(__name__)

Also note that the template folder has to be named templates exactly or Heroku will fail. Again, pretty annoying.

wisenickel
  • 346
  • 4
  • 16