from flask import Flask from werkzeug.routing import BaseConverter app = Flask(__name__) # 自定义一个转换器类 class RegexMobileConverter(BaseConverter): regex = r'1[3-9]\d{9}' # 将转换器注册到app中去 app.url_map.converters['mobile'] = RegexMobileConverter # 路由使用转换器 @app.route('/user/<mobile:temp>') def create_new(temp): print(temp) return f'mobile{temp}' if __name__ == '__main__': print(app.url_map) app.run()