How to make unique short URL with Python?

后端 未结 12 1289
渐次进展
渐次进展 2020-12-02 07:02

How can I make unique URL in Python a la http://imgur.com/gM19g or http://tumblr.com/xzh3bi25y When using uuid from python I get a very large one. I want something shorter f

12条回答
  •  没有蜡笔的小新
    2020-12-02 07:39

    Python's short_url is awesome.

    Here is an example:

    import short_url
    
    id = 20  # your object id
    domain = 'mytiny.domain' 
    
    shortened_url = "http://{}/{}".format(
                                         domain,
                                         short_url.encode_url(id)
                                   )
    

    And to decode the code:

    decoded_id = short_url.decode_url(param)
    

    That's it :)

    Hope this will help.

提交回复
热议问题