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'
and what to be looked something like this:
path = u'/static/media/uploads/gallery/Marrakech, Morocco_be3Ij2N.jpg'
thx.
The path function is contained with the django. urls module within the Django project code base. path is used for routing URLs to the appropriate view functions within a Django application using the URL dispatcher.
Registering custom path convertersA converter is a class that includes the following: A regex class attribute, as a string. A to_python(self, value) method, which handles converting the matched string into the type that should be passed to the view function.
Django path traversal or directory traversal is a web security vulnerability that gives a remote attacker access to files and directories that are stored outside the specified folder to which the application grants access. The attacker can achieve this by manipulating the files with a “dot-dot-slash” (../) sequence.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With