本文介绍了如何解码url到python,django中的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将url转换为路径,我得到的是这个url如下:
Hi I need to convert url to path, what i got is this url as bellow:
url = u'/static/media/uploads/gallery/Marrakech%2C%20Morocco_be3Ij2N.jpg'
如下所示:
path = u'/static/media/uploads/gallery/Marrakech, Morocco_be3Ij2N.jpg'
thx。
推荐答案
使用解码%
-encoded string:
Use urllib.unquote
to decode %
-encoded string:
>>> import urllib
>>> url = u'/static/media/uploads/gallery/Marrakech%2C%20Morocco_be3Ij2N.jpg'
>>> urllib.unquote(url)
u'/static/media/uploads/gallery/Marrakech, Morocco_be3Ij2N.jpg'
使用或,你可以回来:
Using urllib.quote
or urllib.quote_plus
, you can get back:
>>> urllib.quote(u'/static/media/uploads/gallery/Marrakech, Morocco_be3Ij2N.jpg')
'/static/media/uploads/gallery/Marrakech%2C%20Morocco_be3Ij2N.jpg'
这篇关于如何解码url到python,django中的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!