flask: No response and No exception traceback when render_template failed and DEBUG=True

Here is the code:

app.py

from flask import Flask, render_template

app = Flask(__name__)
app.config['DEBUG'] = True

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

if __name__ == '__main__':
    from werkzeug.serving import run_simple
    run_simple('127.0.0.1', 5000, app)

Run it by

python app.py

or

export FLASK_APP=app.py 
flask run

then visit http://127.0.0.1:5000 will see ERR_EMPTY_RESPONSE in browser and nothing in console.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 22 (12 by maintainers)

Most upvoted comments

I found the jinja2.exceptions.TemplateNotFound exception was catch by wrong place

        try:
            execute(self.server.app)
        except (socket.error, socket.timeout) as e: # go here
            self.connection_dropped(e, environ)
        except Exception:
            if self.server.passthrough_errors:
                raise

and in python3.5

issubclass(jinja2.exceptions.TemplateNotFound, socket.error) 
True