forked from liukai234/python_course_record
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
complete templete and init errorpages
- Loading branch information
liukai234
committed
May 30, 2020
1 parent
8ed0597
commit c190a05
Showing
6 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# 自定义错误页面 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hello World!</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 --> |