docs: 2026-04-21作业
This commit is contained in:
13
2026-04-21/2026-04-21_hw_1.py
Normal file
13
2026-04-21/2026-04-21_hw_1.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
from flask import *
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
@app.route("/index/")
|
||||||
|
def index():
|
||||||
|
info = [1, 2, 3, 4, 5]
|
||||||
|
return render_template("2026-04-21_hw_1.html", info=info)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run()
|
||||||
19
2026-04-21/2026-04-21_hw_2.py
Normal file
19
2026-04-21/2026-04-21_hw_2.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
from flask import *
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
@app.route("/filters/")
|
||||||
|
def use_of_filters():
|
||||||
|
num = -2.3
|
||||||
|
li = [2, 1, 5, 6, 7, 4, 4]
|
||||||
|
string = 'flask'
|
||||||
|
return render_template('2026-04-21_hw_2.html', num=num, li=li, string=string)
|
||||||
|
|
||||||
|
@app.template_filter() # 注册自定义过滤器
|
||||||
|
def reverse(data): # 自定义过滤器
|
||||||
|
return data[::-1]
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run()
|
||||||
14
2026-04-21/2026-04-21_hw_3.py
Normal file
14
2026-04-21/2026-04-21_hw_3.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from flask import *
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
count_p = 0
|
||||||
|
|
||||||
|
@app.route("/<int:score>/")
|
||||||
|
@app.route('/query-score/<int:score>/')
|
||||||
|
def query_score(score):
|
||||||
|
return render_template('2026-04-21_hw_3.html',score=score)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run()
|
||||||
BIN
2026-04-21/24计应1_杨近澜_1113_2026-04-21作业.docx
Normal file
BIN
2026-04-21/24计应1_杨近澜_1113_2026-04-21作业.docx
Normal file
Binary file not shown.
11
2026-04-21/templates/2026-04-21_hw_1.html
Normal file
11
2026-04-21/templates/2026-04-21_hw_1.html
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Homework</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Hello Flask!</h1>
|
||||||
|
<h2>info: {{info[3]}}</h2>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
23
2026-04-21/templates/2026-04-21_hw_2.html
Normal file
23
2026-04-21/templates/2026-04-21_hw_2.html
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Homework</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{#返回变量num的绝对值#}
|
||||||
|
<h4>绝对值:{{ num|abs }}</h4>
|
||||||
|
{#将变量num转换为整型#}
|
||||||
|
<h4>转换为整型:{{ num|int }}</h4>
|
||||||
|
{#返回变量li中随机的一个元素#}
|
||||||
|
<h4>获取随机元素:{{ li|random }}</h4>
|
||||||
|
{#返回变量li的长度#}
|
||||||
|
<h4>获取列表长度:{{ li|length }}</h4>
|
||||||
|
<h4>列表排序:{{ li|sort }}</h4>
|
||||||
|
<h4>首字母大写: {{ string|capitalize }}</h4>
|
||||||
|
<h4>字母全大写: {{ string|upper }}</h4>
|
||||||
|
<h4>字符拼接: {{ string|join("-") }}</h4>
|
||||||
|
<h4>列表: {{ li }}</h4>
|
||||||
|
<h4>列表排序:{{ li|reverse }}</h4>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
59
2026-04-21/templates/2026-04-21_hw_3.html
Normal file
59
2026-04-21/templates/2026-04-21_hw_3.html
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<style>
|
||||||
|
.score{
|
||||||
|
width: 12em;
|
||||||
|
height: 4em;
|
||||||
|
line-height: 4em;
|
||||||
|
text-align: center;
|
||||||
|
vertical-align: middle;
|
||||||
|
border: 2px solid black;
|
||||||
|
border-radius: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.excellent{
|
||||||
|
background-color: purple;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lhz{
|
||||||
|
background-color: greenyellow;
|
||||||
|
}
|
||||||
|
|
||||||
|
.middle{
|
||||||
|
background-color: yellow;
|
||||||
|
}
|
||||||
|
|
||||||
|
._60{
|
||||||
|
background-color: orange;
|
||||||
|
}
|
||||||
|
|
||||||
|
._59{
|
||||||
|
background-color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.worse {
|
||||||
|
background-color: red;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
{% if score >= 90 %}
|
||||||
|
<div class="score excellent">优秀</div>
|
||||||
|
{% elif 80 <= score < 90 %}
|
||||||
|
<div class="score lhz">良好</div>
|
||||||
|
{% elif 70 <= score < 80 %}
|
||||||
|
<div class="score middle">中等</div>
|
||||||
|
{% elif 60 <= score < 70 %}
|
||||||
|
<div class="score _60">及格</div>
|
||||||
|
{% elif 59 <= score < 60 %}
|
||||||
|
<div class="score _59">恭喜你,差点就及格了</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="score worse">不及格</div>
|
||||||
|
{% endif %}
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user