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