SpacePatroller
SpacePatroller

Reputation: 53

Flask app runs locally but on Heroku Cannot render template?

For some reason my Flask app runs fine on my local computer but when deployed to heroku I receive a render template error.

procfile: web: gunicorn app:app

Basic file structure:

File Structure


Heroku Log Error

2019-03-20T16:42:53.000000+00:00 app[api]: Build succeeded
2019-03-20T16:42:58.002302+00:00 heroku[router]: at=info method=GET path="/" host=headphones.herokuapp.com request_id=856e996e-9716-4688-8474-49e1102938ae fwd="96.35.158.2" dyno=web.1 connect=1ms service=6ms status=500 bytes=455 protocol=https
2019-03-20T16:42:57.999048+00:00 app[web.1]: [2019-03-20 16:42:57,996] ERROR in app: Exception on / [GET]
2019-03-20T16:42:57.999062+00:00 app[web.1]: Traceback (most recent call last):
2019-03-20T16:42:57.999064+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
2019-03-20T16:42:57.999065+00:00 app[web.1]: response = self.full_dispatch_request()
2019-03-20T16:42:57.999069+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
2019-03-20T16:42:57.999071+00:00 app[web.1]: rv = self.handle_user_exception(e)
2019-03-20T16:42:57.999073+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
2019-03-20T16:42:57.999074+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2019-03-20T16:42:57.999076+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
2019-03-20T16:42:57.999082+00:00 app[web.1]: raise value
2019-03-20T16:42:57.999084+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
2019-03-20T16:42:57.999086+00:00 app[web.1]: rv = self.dispatch_request()
2019-03-20T16:42:57.999088+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
2019-03-20T16:42:57.999089+00:00 app[web.1]: return self.view_functions[rule.endpoint](**req.view_args)
2019-03-20T16:42:57.999091+00:00 app[web.1]: File "/app/app.py", line 55, in home
2019-03-20T16:42:57.999092+00:00 app[web.1]: return render_template("index.html")
2019-03-20T16:42:57.999094+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/templating.py", line 134, in render_template
2019-03-20T16:42:57.999096+00:00 app[web.1]: return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
2019-03-20T16:42:57.999097+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/jinja2/environment.py", line 869, in get_or_select_template
2019-03-20T16:42:57.999099+00:00 app[web.1]: return self.get_template(template_name_or_list, parent, globals)
2019-03-20T16:42:57.999101+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/jinja2/environment.py", line 830, in get_template
2019-03-20T16:42:57.999102+00:00 app[web.1]: return self._load_template(name, self.make_globals(globals))
2019-03-20T16:42:57.999104+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/jinja2/environment.py", line 804, in _load_template
2019-03-20T16:42:57.999105+00:00 app[web.1]: template = self.loader.load(self, name, globals)
2019-03-20T16:42:57.999107+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/jinja2/loaders.py", line 113, in load
2019-03-20T16:42:57.999108+00:00 app[web.1]: source, filename, uptodate = self.get_source(environment, name)
2019-03-20T16:42:57.999110+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/templating.py", line 58, in get_source
2019-03-20T16:42:57.999111+00:00 app[web.1]: return self._get_source_fast(environment, template)
2019-03-20T16:42:57.999113+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/templating.py", line 86, in _get_source_fast
2019-03-20T16:42:57.999114+00:00 app[web.1]: raise TemplateNotFound(template)
2019-03-20T16:42:57.999120+00:00 app[web.1]: jinja2.exceptions.TemplateNotFound: index.html
2019-03-20T16:42:58.000010+00:00 app[web.1]: 10.69.213.200 - - [20/Mar/2019:16:42:57 +0000] "GET / HTTP/1.1" 500 290 "https://dashboard.heroku.com/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
2019-03-20T16:42:58.180976+00:00 app[web.1]: 10.69.213.200 - - [20/Mar/2019:16:42:58 +0000] "GET /favicon.ico HTTP/1.1" 404 232 "https://headphones.herokuapp.com/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
2019-03-20T16:42:58.183263+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=headphones.herokuapp.com request_id=3bb6ecd2-778e-499e-b0e6-72913e8c4a08 fwd="96.35.158.2" dyno=web.1 connect=1ms service=4ms status=404 bytes=385 protocol=https

Upvotes: 0

Views: 640

Answers (2)

SpacePatroller
SpacePatroller

Reputation: 53

@elias Well I wish I tried that first. Not sure what it ending up being but I just rebuilt the entire app one part at time deploying to heroku as I added in parts to see what may have been causing the issue. Unfortunately I never did, however the app works now.

So yeah something was not being pushed up when I tried uploading the app as whole.

Thank you to everyone for the assistance on my first post!

Upvotes: 0

Elias Dorneles
Elias Dorneles

Reputation: 23866

It looks like the files weren't all sent to Heroku.

If you're deploying with git, make sure that all files are being shipped to the slug.

In your place, I'd try inspecting the contents of the slug by doing heroku run bash -a name-of-your-app and check if all files are where you'd expect them to be.

Upvotes: 1

Related Questions