Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8044183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:08:45+00:00 2026-06-05T05:08:45+00:00

I am trying to form URLs from different pieces, and having trouble understanding the

  • 0

I am trying to form URLs from different pieces, and having trouble understanding the behavior of this method. For example:

Python 3.x

from urllib.parse import urljoin

>>> urljoin('some', 'thing')
'thing'
>>> urljoin('http://some', 'thing')
'http://some/thing'
>>> urljoin('http://some/more', 'thing')
'http://some/thing'
>>> urljoin('http://some/more/', 'thing') # just a tad / after 'more'
'http://some/more/thing'
urljoin('http://some/more/', '/thing')
'http://some/thing'

Can you explain the exact behavior of this method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:08:48+00:00Added an answer on June 5, 2026 at 5:08 am

    The best way (for me) to think of this is the first argument, base is like the page you are on in your browser. The second argument url is the href of an anchor on that page. The result is the final url to which you will be directed should you click.

    >>> urljoin('some', 'thing')
    'thing'
    

    This one makes sense given my description. Though one would hope base includes a scheme and domain.

    >>> urljoin('http://some', 'thing')
    'http://some/thing'
    

    If you are on a vhost some, and there is an anchor like <a href='thing'>Foo</a> then the link will take you to http://some/thing

    >>> urljoin('http://some/more', 'thing')
    'http://some/thing'
    

    We are on some/more here, so a relative link of thing will take us to /some/thing

    >>> urljoin('http://some/more/', 'thing') # just a tad / after 'more'
    'http://some/more/thing'
    

    Here, we aren’t on some/more, we are on some/more/ which is different. Now, our relative link will take us to some/more/thing

    >>> urljoin('http://some/more/', '/thing')
    'http://some/thing'
    

    And lastly. If on some/more/ and the href is to /thing, you will be linked to some/thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to rewrite urls from the form: https://example.com/about to the form http://example.com/about using
I'm trying to use urls on my site like example.com/@lorem-ipsum-dolor instead of example.com/tag/lorem-ipsum-dolor form.
I'm trying to use urlretrieve to download files from urls that take the form:
I am trying to rewrite my urls to go from /controller/method to index.php?/controller/method, and
I've a field in the form,trying to get this value using jquery.It is always
I am trying to intercept form submits from webpages I dont control. My current
Trying to customize Symfony2 form to produce html code looking like the following example:
Trying to implement clean URLs (without .form, .do, etc.) with Spring MVC 3.0 (actually
I am trying to enable sluggified URLs in Django of the form that SO
I'm trying to test if for existing URLs in a user form field and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.