From c190a05765a86b10a9886dace87a21c9ad8efb07 Mon Sep 17 00:00:00 2001 From: liukai234 <2679327337@qq.com> Date: Sat, 30 May 2020 09:25:00 +0800 Subject: [PATCH] complete templete and init errorpages --- python_web/flasky/errorpages.py | 1 + python_web/flasky/rendering.py | 0 python_web/flasky/template.py | 21 ++++++++++++++++++++- python_web/flasky/templates/contorl.html | 16 ++++++++++++++++ python_web/flasky/templates/index.html | 1 + python_web/flasky/templates/user.html | 13 +++++++++++++ 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 python_web/flasky/errorpages.py create mode 100644 python_web/flasky/rendering.py create mode 100644 python_web/flasky/templates/contorl.html create mode 100644 python_web/flasky/templates/index.html create mode 100644 python_web/flasky/templates/user.html diff --git a/python_web/flasky/errorpages.py b/python_web/flasky/errorpages.py new file mode 100644 index 0000000..b273286 --- /dev/null +++ b/python_web/flasky/errorpages.py @@ -0,0 +1 @@ +# 自定义错误页面 \ No newline at end of file diff --git a/python_web/flasky/rendering.py b/python_web/flasky/rendering.py new file mode 100644 index 0000000..e69de29 diff --git a/python_web/flasky/template.py b/python_web/flasky/template.py index ba292cf..023a605 100644 --- a/python_web/flasky/template.py +++ b/python_web/flasky/template.py @@ -1 +1,20 @@ -# flask extenion \ No newline at end of file +# flask extenion +# Jinja2 模板引擎 + +from flask import Flask, render_template + +app = Flask(__name__) + +@app.route('/') +def index(): + # 使用的默认路径是 ./templates/index.html + return render_template('index.html') + +@app.route('/user/') +def user(name): + # 左边的参数表示模板中使用的占位符,右边表示当前作用域中的变量 + # 两边使用相同的变量名很常见,但不是强制要求 + return render_template('user.html', name = name) + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=19722, debug=True) \ No newline at end of file diff --git a/python_web/flasky/templates/contorl.html b/python_web/flasky/templates/contorl.html new file mode 100644 index 0000000..f37b419 --- /dev/null +++ b/python_web/flasky/templates/contorl.html @@ -0,0 +1,16 @@ + +{% if user %} + Hello, {{ user }}! +{% else %} + Hello, Stranger! +{% endif %} + + + + + +{% include 'commom.html' %} \ No newline at end of file diff --git a/python_web/flasky/templates/index.html b/python_web/flasky/templates/index.html new file mode 100644 index 0000000..de8b69b --- /dev/null +++ b/python_web/flasky/templates/index.html @@ -0,0 +1 @@ +

Hello World!

diff --git a/python_web/flasky/templates/user.html b/python_web/flasky/templates/user.html new file mode 100644 index 0000000..2b98916 --- /dev/null +++ b/python_web/flasky/templates/user.html @@ -0,0 +1,13 @@ +

Hello {{ name }}!

+ + + + + + + + + \ No newline at end of file