Compare commits

...

9 Commits

Author SHA1 Message Date
546f231698 docs: 2026-05-19作业 2026-05-26 01:18:33 +08:00
8dd1fae2e1 docs: 2026-05-12作业 2026-05-19 00:38:45 +08:00
6b51126213 docs: 2026-04-28作业 2026-05-11 23:07:40 +08:00
dd21ddbaef docs: 2026-04-21作业 2026-04-27 22:12:44 +08:00
b0db5b3239 docs: 2026-04-14作业 2026-04-20 20:14:49 +08:00
af13f500e1 docs: PPT++ 2026-04-14 13:01:02 +08:00
2ae54f2f06 docs: 2026-04-07作业 2026-04-13 20:03:02 +08:00
5dcc0fcada docs: 2026-03-24作业_word文档 2026-03-30 20:43:56 +08:00
243711134c docs: 2026-03-10文件 2026-03-30 20:27:42 +08:00
51 changed files with 685 additions and 0 deletions

10
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,10 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 已忽略包含查询文件的默认文件夹
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.14" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/myPythonWebHomework.iml" filepath="$PROJECT_DIR$/.idea/myPythonWebHomework.iml" />
</modules>
</component>
</project>

8
.idea/myPythonWebHomework.iml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.14" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

7
2026-03-10/c1.py Normal file
View File

@@ -0,0 +1,7 @@
code = """code = "__code__"
ref = '"'
sign = "__" + "code" + "__"
print(code.replace(sign, ref + ref + code + ref + ref), end="")"""
ref = '"'
sign = "__" + "code" + "__"
print(code.replace(sign, ref + ref + code + ref + ref), end="")

7
2026-03-10/c2.py Normal file
View File

@@ -0,0 +1,7 @@
code = """code = "__code__"
ref = '"'
sign = "__" + "code" + "__"
print(code.replace(sign, ref + ref + code + ref + ref), end="")"""
ref = '"'
sign = "__" + "code" + "__"
print(code.replace(sign, ref + ref + code + ref + ref), end="")

7
2026-03-10/c3.py Normal file
View File

@@ -0,0 +1,7 @@
code = """code = "__code__"
ref = '"'
sign = "__" + "code" + "__"
print(code.replace(sign, ref + ref + code + ref + ref), end="")"""
ref = '"'
sign = "__" + "code" + "__"
print(code.replace(sign, ref + ref + code + ref + ref), end="")

7
2026-03-10/c4.py Normal file
View File

@@ -0,0 +1,7 @@
code = """code = "__code__"
ref = '"'
sign = "__" + "code" + "__"
print(code.replace(sign, ref + ref + code + ref + ref), end="")"""
ref = '"'
sign = "__" + "code" + "__"
print(code.replace(sign, ref + ref + code + ref + ref), end="")

7
2026-03-10/c5.py Normal file
View File

@@ -0,0 +1,7 @@
code = """code = "__code__"
ref = '"'
sign = "__" + "code" + "__"
print(code.replace(sign, ref + ref + code + ref + ref), end="")"""
ref = '"'
sign = "__" + "code" + "__"
print(code.replace(sign, ref + ref + code + ref + ref), end="")

7
2026-03-10/mypython22.py Normal file
View File

@@ -0,0 +1,7 @@
code = """code = "__code__"
ref = '"'
sign = "__" + "code" + "__"
print(code.replace(sign, ref + ref + code + ref + ref), end="")"""
ref = '"'
sign = "__" + "code" + "__"
print(code.replace(sign, ref + ref + code + ref + ref), end="")

View File

@@ -0,0 +1,16 @@
from flask import Flask
app = Flask(__name__)
@app.route("/liuhz1/")
def lhz():
return "哇! 你找到lhz啦! "
app.add_url_rule(rule = "/liuhz2/", view_func= lhz)
def main():
app.run()
if __name__ == "__main__":
main()

36
2026-04-07/main.py Normal file
View File

@@ -0,0 +1,36 @@
from flask import Flask
from werkzeug.routing import BaseConverter
app = Flask(__name__)
@app.route("/")
def hello_flask():
return "<p>Hello, Flask!</p>"
@app.route("/index/")
def index():
return "<h1>这是首页!</h1>"
@app.route("/api/lhz/")
def lhz():
return """ <div>这是LiuHanZheng</div>
<div>Length: 1cm</div>"""
app.add_url_rule(rule='/lhz/', view_func=lhz)
@app.route("/pages/<int:page>/")
def page_num(page):
return f"<div>当前为第{page}页</div>"
class MobileConverter(BaseConverter): # 自定义转换器
regex = "1[3-9]\d{9}$" # 定义匹配手机号码的规则
app.url_map.converters["mobile"] = MobileConverter # 添加到转换器字典
@app.route("/user/<mobile:mobile>/")
def mobile_index(mobile):
return f'手机号为:{mobile}'
if __name__ == "__main__":
app.run(port=1145)

BIN
2026-04-07/requirements.txt Normal file

Binary file not shown.

View File

@@ -0,0 +1,32 @@
from flask import Flask, after_this_request
app = Flask(__name__)
@app.before_first_request
def before_first_request():
print('这是请求钩子 before_first_request 注册的函数')
@app.before_request
def before_request():
print('这是请求钩子 before_request 注册的函数')
@app.route('/index')
def index():
print('hello flask')
@after_this_request
def after_this_request_func(response):
print('这是请求钩子 after_this_request_func 注册的函数')
return response
return 'hello flask'
@app.after_request
def after_request(response):
print('这是请求钩子 after_request 注册的函数')
return response
@app.teardown_request
def teardown_request(error):
print('这是请求钩子 teardown_request 注册的函数')
if __name__ == '__main__':
app.run()

View File

@@ -0,0 +1,26 @@
from flask import Flask, url_for, request, redirect, session
app = Flask(__name__)
app.secret_key = 'Your_secret_key$^52@!'
@app.route('/index')
def index():
if 'username' in session:
return f'你好,{session.get("username")}'
return redirect(url_for("login"))
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
session['username'] = request.form['username']
return redirect(url_for('index'))
# 当发送GET请求时页面显示输入框和"登录"按钮
return '''
<form method="post">
<p><input type=text name=username>
<p><input type=submit value=登录>
</form>
'''
if __name__ == '__main__':
app.run()

Binary file not shown.

View 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()

View 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()

View 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()

View 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>

View 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>

View 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>

View File

@@ -0,0 +1,32 @@
from flask import Flask, render_template
from flask import flash, redirect, session, request, url_for
app = Flask(__name__)
app.secret_key = 'Your_secret_key&^52@!' # 设置secret_key
@app.route('/home')
@app.route('/')
def home_page():
username = session.get('username')
# 判断session是否存储username的数据
if 'username' in session:
return render_template('hw_t1_home_page.html', username=username)
return redirect(url_for('login')) # 重定向到login页面
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
if request.form['username'] != 'admin' or \
request.form['password'] != '123':
flash('用户名或密码错误', category='error')
else:
session['username'] = request.form['username']
session['password'] = request.form['password']
flash('恭喜您,登录成功', category='info')
return redirect(url_for('home_page'))
return render_template('hw_t1_login.html')
if __name__ == '__main__':
app.run(port=80)

View File

@@ -0,0 +1,13 @@
from flask import *
app = Flask(__name__)
@app.route('/')
@app.route('/static-file')
def load_staticfile():
return render_template('hw_t2.html')
if __name__ == "__main__":
app.run(port=80)

BIN
2026-04-28/static/flask.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3</title>
</head>
<body>
<h2>主页</h2>
{% for message in get_flashed_messages(category_filter = ('info')) %}
<span>{{ message }}</span>
{% endfor %}
<p>欢迎用户:{{ username }}</p>
</body>
</html>

View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2>用户登录</h2>
{% for message in get_flashed_messages(category_filter = ('error')) %}
<p class="error" style="color: red;">{{ message }}</p>
{% endfor %}
<form action="" method="post" class="form">
<span>用户名:</span><br>
<input type="text" name="username"><br>
<span>密码:</span><br>
<input type="password" name="password"><br>
<p><input type="submit" value="登录"></p>
</form>
</body>
</html>

View File

@@ -0,0 +1,180 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hw</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: linear-gradient(45deg, #0f0c29, #302b63, #24243e, #1c1c3c, #0f0c29);
background-size: 400% 400%;
animation: gradientBG 10s ease infinite;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
overflow: hidden;
position: relative;
}
@keyframes gradientBG {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
/* 浮动粒子 */
.particle {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.1);
animation: floatUp linear infinite;
bottom: -10px;
}
@keyframes floatUp {
0% { transform: translateY(0) scale(1); opacity: 0; }
10% { opacity: 0.6; }
90% { opacity: 0.6; }
100% { transform: translateY(-110vh) scale(0.5); opacity: 0; }
}
.card {
position: relative;
z-index: 10;
text-align: center;
padding: 50px 60px;
background: rgba(255, 255, 255, 0.05);
border-radius: 24px;
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border: 1px solid rgba(255, 255, 255, 0.15);
box-shadow:
0 8px 32px rgba(0, 0, 0, 0.3),
0 0 60px rgba(100, 200, 255, 0.1);
transition: transform 0.4s ease, box-shadow 0.4s ease;
}
.card:hover {
transform: translateY(-10px) scale(1.02);
box-shadow:
0 20px 60px rgba(0, 0, 0, 0.4),
0 0 80px rgba(100, 200, 255, 0.25);
}
p {
font-size: 2.5rem;
font-weight: 900;
letter-spacing: 4px;
text-transform: uppercase;
color: #fff;
text-shadow:
0 0 10px rgba(0, 255, 255, 0.8),
0 0 20px rgba(0, 255, 255, 0.6),
0 0 40px rgba(0, 255, 255, 0.4),
0 0 80px rgba(0, 255, 255, 0.2);
animation: flicker 3s infinite alternate;
margin-bottom: 30px;
}
@keyframes flicker {
0%, 18%, 22%, 25%, 53%, 57%, 100% {
text-shadow:
0 0 10px rgba(0, 255, 255, 0.8),
0 0 20px rgba(0, 255, 255, 0.6),
0 0 40px rgba(0, 255, 255, 0.4),
0 0 80px rgba(0, 255, 255, 0.2);
}
20%, 24%, 55% {
text-shadow:
0 0 5px rgba(0, 255, 255, 0.5),
0 0 10px rgba(0, 255, 255, 0.3);
}
}
.img-wrapper {
position: relative;
display: inline-block;
border-radius: 20px;
padding: 6px;
background: linear-gradient(45deg, #00f260, #0575e6, #ff00cc, #333399);
background-size: 300% 300%;
animation: borderMove 4s linear infinite;
box-shadow: 0 0 30px rgba(0, 200, 255, 0.3);
}
@keyframes borderMove {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
.img-wrapper img {
display: block;
max-width: 300px;
border-radius: 16px;
transition: transform 0.5s ease, filter 0.5s ease;
filter: brightness(1.1) contrast(1.1);
}
.img-wrapper:hover img {
transform: scale(1.08) rotate(2deg);
filter: brightness(1.2) contrast(1.2) saturate(1.3);
}
/* 扫描线效果 */
.scanline {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(
to bottom,
rgba(255,255,255,0),
rgba(255,255,255,0) 50%,
rgba(0,0,0,0.05) 50%,
rgba(0,0,0,0.05)
);
background-size: 100% 4px;
pointer-events: none;
z-index: 999;
opacity: 0.3;
}
</style>
</head>
<body>
<!-- 浮动粒子 -->
<script>
(function() {
for (let i = 0; i < 30; i++) {
const p = document.createElement('div');
p.className = 'particle';
const size = Math.random() * 6 + 2;
p.style.width = size + 'px';
p.style.height = size + 'px';
p.style.left = Math.random() * 100 + 'vw';
p.style.animationDuration = (Math.random() * 8 + 4) + 's';
p.style.animationDelay = (Math.random() * 5) + 's';
document.body.appendChild(p);
}
})();
</script>
<div class="scanline"></div>
<div class="card">
<p>Flask-Logo图片</p>
<div class="img-wrapper">
<img src="{{ url_for('static',filename='flask.png') }}" alt="Flask Logo">
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,29 @@
from flask import Flask, render_template
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField
from wtforms.validators import DataRequired, Length, EqualTo
app = Flask(__name__)
app.secret_key = '34sdfji9453#$@'
class RegisterForm(FlaskForm):
username = StringField(label='用户名:',
validators=[DataRequired(message='用户名不能为空'),
Length(3, 15, message='长度应该为3~15个字符')])
password = PasswordField('密码:',
validators=[DataRequired(message='密码不能为空')])
password2 = PasswordField('确认密码:',
validators=[DataRequired(message='密码不能为空'),
EqualTo('password', message='两次密码不一致')])
submit = SubmitField('注册')
@app.route('/register', methods=['GET', 'POST'])
def register():
form = RegisterForm()
return render_template('register_wtf.html', form=form)
if __name__ == '__main__':
app.run(debug=True)

View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>注册页面</h1>
<form method="post">
{{ form.csrf_token }}
{#获取username对应的标签名称#}
<span>{{ form.username.label }}</span><br>
{#调用表单字段#}
{{ form.username }}<br>
<span>{{ form.password.label }}</span><br>
{{ form.password }}<br>
<span>{{ form.password2.label }}</span><br>
{{ form.password2 }}<br>
<p>{{ form.submit }}</p>
</form>
</body>
</html>

View File

@@ -0,0 +1,25 @@
from flask.views import MethodView
from flask import Flask, render_template, request
class LoginView(MethodView):
def get(self):
# 处理 GET 请求:展示登录页面
return render_template('login.html')
def post(self):
# 处理 POST 请求:获取表单数据并校验
username = request.form.get('username') # 获取输入的用户名
password = request.form.get('password') # 获取输入的密码
# 判断用户名是否为 flask、密码是否为 123
if username == 'flask' and password == '123':
return f'用户:{username}登录成功。'
else:
return '用户名或密码错误,请重新登录。'
app = Flask(__name__)
# 将类视图与 URL 进行映射
app.add_url_rule('/login', view_func=LoginView.as_view('login'))
if __name__ == '__main__':
app.run()

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hw</title>
</head>
<body>
<form action="" method="post">
<span>用户名:</span><br>
<input type="text" name="username"><br>
<span>密码:</span><br>
<input type="password" name="password"><br>
<p><input type="submit" value="登录"></p>
</form>
</body>
</html>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.