From 02a1b3404eb6283f7247bb42c8616fbbd2f3306d Mon Sep 17 00:00:00 2001 From: tmeissner Date: Mon, 8 Oct 2018 22:15:14 +0200 Subject: [PATCH] Chapter 3: Templates (3a) --- hello.py | 7 ++++--- templates/index.html | 1 + templates/user.html | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 templates/index.html create mode 100644 templates/user.html diff --git a/hello.py b/hello.py index 06f1145..e46999a 100644 --- a/hello.py +++ b/hello.py @@ -1,12 +1,13 @@ -from flask import Flask +from flask import Flask, render_template + app = Flask(__name__) @app.route('/') def index(): - return '

Hello World!

' + return render_template('index.html') @app.route('/user/') def user(name): - return '

Hello, {}!

'.format(name) + return render_template('user.html', name=name) diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..ba7c290 --- /dev/null +++ b/templates/index.html @@ -0,0 +1 @@ +

Hello World!

\ No newline at end of file diff --git a/templates/user.html b/templates/user.html new file mode 100644 index 0000000..5c637d1 --- /dev/null +++ b/templates/user.html @@ -0,0 +1 @@ +

Hello, {{ name }}!

\ No newline at end of file