docs: 2026-04-07作业

This commit is contained in:
2026-04-13 20:03:02 +08:00
parent 5dcc0fcada
commit 2ae54f2f06
10 changed files with 94 additions and 0 deletions

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)