安装
pip install Flask-ShortUrl
代码示例
# -*- coding: utf-8 -*- from flask import Flask from flask_shorturl import ShortUrl app = Flask(__name__) short = ShortUrl(app) # int转url url = short.encode_url(123) # url转int uid = short.decode_url(url) print(url, uid) # 9epgb 123 @app.route('/<short_url:uid>') def decode_url(uid: int): """ 通过路由匹配器转换 url->int http://127.0.0.1:5000/9epgb :param uid: 9epgb :return: 123 """ return str(uid) if __name__ == '__main__': app.run(debug=True)