2

What does this URL pattern mean?

url(r'^(?P<itemnum>\d+)/$', views.confirm, name='confirm-page'),
)

How can I activate it?

1
  • ... and name='confirm-page' used to set name for this uri. It used in redirects, templates to provide <a href={% url 'confirm-page' 75%}... and etc. Commented Jul 29, 2013 at 20:21

2 Answers 2

4

A request to /75/ or /3/ would call the function views.confirm(itemnum='75') or views.confirm(itemnum='3').

The variable itemnum can hold any number.

You can read more about url dispatcher here.

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

Comments

4

Let's see:

  • ^ means the beginning of a string
  • (?P<itemnum>\d+) is a named saving group that in your case matches 1 or more digits in a row. The captured part of the url will be passed as a keyword argument to your views.confirm function:

    def confirm(request, itemnum=None):
        print itemnum
        ...
    
  • $ means the end of a string

Example: 2013 will be captured from http://mydomain.com/2013/.

1 Comment

I would like to add this URL for reference

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.