[Django]-Django : extract a path from a full URL

10👍

You can use urlparse module to extract the path:

try:
    from urllib.parse import urlparse  # Python 3 
except ImportError:
    from urlparse import urlparse  # Python 2

parsed = urlparse('http://stackoverflow.com/questions/32809595')
print(parsed.path)

Output:

'/questions/32809595'
👤ahmed

Leave a comment