Python:Flask-ShortUrl短连接转换器

Flask-ShortUrl短连接转换器

文档:https://github.com/lepture/flask-shorturl

安装

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)
上一篇:关于网页中实现套打得解决办法


下一篇:能Ping通,能DNS解析,不能打开网页的解决办法