Name
urljoin
Synopsis
urljoin(base_url_string
,relative_url_string
)
Returns a URL string u
, obtained by
joining relative_url_string
, which may be
relative, with base_url_string
. The
joining procedure that urljoin
performs to obtain
its result u
may be summarized as follows:
When either of the argument strings is empty,
u
is the other argument.When
relative_url_string
explicitly specifies a scheme different from that ofbase_url_string
,u
isrelative_url_string
. Otherwise,u
’s scheme is that ofbase_url_string
.When the scheme does not allow relative URLs (e.g.,
mailto
), orrelative_url_string
explicitly specifies a location (even when it is the same as the location ofbase_url_string
), all other components ofu
are those ofrelative_url_string
. Otherwise,u
’s location is that ofbase_url_string
.u
’s path is obtained by joining the paths ofbase_url_string
andrelative_url_string
according to standard syntax for absolute and relative URL paths. For example:import urlparse urlparse.urljoin( 'http://somehost.com/some/path/here', '../other/path') # Result is: 'http://somehost.com/some/other/path'
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.