Skip to content

Instantly share code, notes, and snippets.

@medwards
Created June 28, 2015 21:55
Show Gist options
  • Save medwards/be80a7a9ea64eda60009 to your computer and use it in GitHub Desktop.
Save medwards/be80a7a9ea64eda60009 to your computer and use it in GitHub Desktop.
import urlparse
host = 'http://example.com'
endpoint = 'endpoint'
thing_id = 226
print "naive urljoin: ", urlparse.urljoin(host, endpoint, thing_id)
print "less naive urljoin: ", urlparse.urljoin(urlparse.urljoin(host, endpoint), str(thing_id))
print "ugly working urljoin: ", urlparse.urljoin(host, "%s/%s" % (endpoint, thing_id))
"""
naive urljoin: http://example.com/endpoint
less naive urljoin: http://example.com/226
ugly working urljoin: http://example.com/endpoint/226
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment