Skip to content

Commit

Permalink
complete templete and init errorpages
Browse files Browse the repository at this point in the history
  • Loading branch information
liukai234 committed May 30, 2020
1 parent 8ed0597 commit c190a05
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions python_web/flasky/errorpages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 自定义错误页面
Empty file added python_web/flasky/rendering.py
Empty file.
21 changes: 20 additions & 1 deletion python_web/flasky/template.py
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
# flask extenion
# 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/<name>')
def user(name):
# 左边的参数表示模板中使用的占位符,右边表示当前作用域中的变量
# 两边使用相同的变量名很常见,但不是强制要求
return render_template('user.html', name = name)

if __name__ == "__main__":
app.run(host="0.0.0.0", port=19722, debug=True)
16 changes: 16 additions & 0 deletions python_web/flasky/templates/contorl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--条件控制-->
{% if user %}
Hello, {{ user }}!
{% else %}
Hello, Stranger!
{% endif %}

<!--循环控制-->
<ul>
{% for comment in comments %}
<li>{{ comment }}</li>
{% endfor %}
</ul>

<!--引入文件,避免过多重复-->
{% include 'commom.html' %}
1 change: 1 addition & 0 deletions python_web/flasky/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello World!</h1>
13 changes: 13 additions & 0 deletions python_web/flasky/templates/user.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h1>Hello {{ name }}!</h1>

<!--Jinja2能识别所有类型的变量,甚至是一些复杂的类型,录入列表字典和对象-->
<!-- <p>A value from a dictionary:{{ mydict['key'] }}</p>
<p>A value from a list:{{ mylist[3] }}</p>
<p>A value from a list, with a variable index:{{ mylist[myintvar] }}</p>
<p>A value from an object's method:{{ myobj.somemethod() }}</p> -->

<!--变量的值可以用过滤器修改-->
<!-- <h1>Hello {{ name|capitalize }}!</h1> -->

<!--常用过滤器-->
<!-- safe capitalize lower upper title trim striptags -->

0 comments on commit c190a05

Please sign in to comment.