1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route("/")
def home():
content = 'Flask-Jinja-Test'
return render_template(
"hello.html",
title='Hello',
content=content
)
@app.route("/handled")
def bad_route_handled():
try:
raise ArithmeticError('Hello')
except Exception:
pass
return render_template(
"hello.html",
title='Hello',
content='Flask-Jinja-Test'
)
@app.route("/unhandled")
def bad_route_unhandled():
raise ArithmeticError('Hello')
return render_template(
"hello.html",
title='Hello',
content='Flask-Jinja-Test'
)
@app.route("/bad_template")
def bad_template():
return render_template(
"bad.html",
title='Bad',
content='Flask-Jinja-Test'
)
@app.route("/exit")
def exit_app():
from flask import request
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('No shutdown')
func()
return 'Done'
if __name__ == '__main__':
app.run()
|