3

This is a a basic question but I'm having trouble finding the answer in in docs:

Lets say I have a url like:

http://example.com/part1/part2

and I have:

urlpatterns = patterns('',
    # Examples:
    url(r'^$', 'xxx', name='yyy'),

)

What part of the url string above is attempted to be matched by the regex between ^ and $?

I've read through numerous sources and docs including:

1 Answer 1

4

This is stated in the documentation clearly:

The URLconf searches against the requested URL, as a normal Python string. This does not include GET or POST parameters, or the domain name.

For example, in a request to http://www.example.com/myapp/, the URLconf will look for myapp/.

In a request to http://www.example.com/myapp/?page=3, the URLconf will look for myapp/.

The URLconf doesn’t look at the request method. In other words, all request methods – POST, GET, HEAD, etc. – will be routed to the same function for the same URL.

In your case, part1/part2 string would be searched against.

Sign up to request clarification or add additional context in comments.

7 Comments

Thank you Alecxe for pointing out the location of that explanation in the docs. I have a follow up question. At the explanation it states: "The URLconf searches against the requested URL," does the URL refer to just "part1/part2" I thought a URL refers to "example.com/part1/part2"
@user61629 you are welcome. domain name is not included in the check, see This does not include GET or POST parameters, or the domain name.
Thank you, So for my understanding , if django defines the URL as "part1/part2" , what does it call "example.com/part1/part2" ?
@user61629 well, they URL is definitely the whole string http://example.com/part1/part2, part1/part2 can be referred as "path", but it is just a part of a URL.
Thanks for your help. I find it a bit confusing though, especially for beginners.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.