Search code examples
pythonherokuflaskinternal-server-error

500 internal server error on heroku with flask


I get a 500 internal server error on Heroku with Flask. My app runs perfectly fine on localhost http://127.0.0.1:5000/. Tried searching extensively on Stack Overflow but didn't find an answer.

Here's the heroku log

2016-02-23T09:27:56.657837+00:00 app[web.1]:   File "/app/servertest.py", line 18, in hello_world
2016-02-23T09:27:56.657837+00:00 app[web.1]:     return render_template('index.html')
2016-02-23T09:27:56.657838+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/templating.py", line 127, in render_template
2016-02-23T09:27:56.657838+00:00 app[web.1]:     return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
2016-02-23T09:27:56.657839+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/jinja2/environment.py", line 851, in get_or_select_template
2016-02-23T09:27:56.657840+00:00 app[web.1]:     return self.get_template(template_name_or_list, parent, globals)
2016-02-23T09:27:56.657841+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/jinja2/environment.py", line 812, in get_template
2016-02-23T09:27:56.657842+00:00 app[web.1]:     return self._load_template(name, self.make_globals(globals))
2016-02-23T09:27:56.657842+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/jinja2/environment.py", line 774, in _load_template
2016-02-23T09:27:56.657843+00:00 app[web.1]:     cache_key = self.loader.get_source(self, name)[1]
2016-02-23T09:27:56.657844+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/templating.py", line 64, in get_source
2016-02-23T09:27:56.657844+00:00 app[web.1]:     raise TemplateNotFound(template)
2016-02-23T09:27:56.657845+00:00 app[web.1]: TemplateNotFound: index.html

Here's a bit of my code

from flask import Flask, request, send_from_directory, send_file, jsonify, render_template
from PIL import Image
import commands
import requests
import json
import os
from werkzeug import secure_filename
import sys
import logging

app = Flask(__name__)

app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.ERROR)

@app.route('/')
def hello_world():
    return render_template('index.html')

Here's my file tree

+-- app
|   flaskFile.py
|   templates
|   +-- index.html
|   +-- ...

Even tried app = Flask(__name__,template_folder='templates'), but it did not work. Please help.


Solution

  • It works for me now. I had a renaming issue on remote since I did not rename using CLI. If you are reading this, always use CLI.