From a163758ed0b01ef010130e1edca3490b5d9aff74 Mon Sep 17 00:00:00 2001 From: zart2007 Date: Mon, 17 Apr 2023 15:44:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 13 ++++++++++++- templates/index.html | 12 +++++++----- templates/table.html | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 templates/table.html diff --git a/app.py b/app.py index c415770..f0b0fda 100644 --- a/app.py +++ b/app.py @@ -17,10 +17,21 @@ app = Flask(__name__) def hello(): return "

hello

" -@app.route('/hello/') +@app.route('/hello//') def hello_2(name): return render_template('index.html', name=name) +@app.route("/99/") +def multi(): + table = [] + for i in range(1, 10): + row = [] + for j in range(1, i + 1): + row.append('{}x{}={}'.format(j, i, i * j)) + table.append(row) + return render_template('table.html', table=table) + + if __name__ == '__main__': app.run(host="0.0.0.0", port=8080, debug=True) \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 2c949f3..26718e9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,14 +1,16 @@ + Hello from Flask + -{% if name %} -

Hello {{ name }}

-{% else %} -

Hello World!

-{% endif %} + {% if name %} +

Hello {{ name }}

+ {% else %} +

Hello World!

+ {% endif %} \ No newline at end of file diff --git a/templates/table.html b/templates/table.html new file mode 100644 index 0000000..12ee90e --- /dev/null +++ b/templates/table.html @@ -0,0 +1,14 @@ + + + + + 99乘法表 + + +{% for row in table %} +
    {{ row.0 }} {{ row.1 }} {{ row.2 }} {{ row.3 }} {{ row.4 }} {{ row.5 }} {{ row.6 }} {{ row.7 }} {{ row.8 }} {{ row.9 }}
+ +{% endfor %} + + + \ No newline at end of file