I was going through the django tutorial and though now almost everything there seems pretty clear, I am having trouble understanding the regex while matching the urls :
r'^(?P<poll_id>\d+)/$
what does (?P<poll_id>\d+) do ?
I am understanding that after stripping off the "34/" from "polls/34/", The polls.url is being called and there the keyword urlpatterns is being looked for , but how does poll_id get this value 34 ?
I know only a bit of regex, so thats why it might be hard for me to read.
Also, here is the reference that I am using for this question :Tutorial Part3
It’s a regex that takes the
poll_id(a number) as a variable.The corresponding view is:
Now when you go to
example.com/polls/34/, it knows you are looking forpollnumber34, and it brings that in to the view as thepoll_id.So in your view,
poll_id = 34. This allows you to display or manipulate this specific poll.Essentially the point of the regex in this case is to allow you to view a large number of specific polls without having to create an explicit url for each one.
To clarify, this regex is saying take any number
\d+, save it aspoll_id, and proceed to this view with thatpoll_id.