Django URL with a number of parameters

Source: Internet
Author: User

URLs, like the collaterals, tightly link the various parts of Django's large framework into a single population, so it's a good idea to understand that Django starts from a URL.

The relationship between the general view template URL is not discussed here, and the following is a sample of the passing of the parameters in the URL.


1. Simple number of parameters to call

URL (R ' ^articles/(\d{4})/(\d{2})/$ ',' news.views.month_archive '),

For the above URL, suppose to parse with/articles/2005/03/. Finally, the view is resolved to the

news.views.month_archive (Request, ' 2005 ', ' a ') . 


2. Call with named number of parameters

The above is simple, but do not have the name after the look is always confusing, not a good programming habit, first introduce the rules of the next number of names

(? P<name>pattern)

Same or the same logical example as before

URL (R ' ^articles/(? P<YEAR>\D{4})/(?

P<MONTH>\D{2})/$ ',' news.views.month_archive '),

Samewith/articles/2005/03/to parse, and finally resolves to

News.views.month_archive (request,year= ' 2005 ', month= ' 03 ')

It's a little clearer than it was before.


3. For URLs in template mappings

For the sample in 1:

{%url ' path.to.some_view 'v1 v2%}

For the sample in 2:

{%url ' path.to.some_view 'arg1=v1 arg2=v2 %}


Django URL with a number of parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.