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)