Nameless and famous grouping grouping

Nameless and famous grouping grouping

Unknown group:

无名分组
url(r'^test/(\d+)/', views.test)
会将括号内匹配到的内容当做 位置参数 传递给后面的视图函数test(request,args)

Parenthesis is the regular packet inside, \ d is as long as the numbers on the line, + represents a one to infinity,? Is zero or one, * is a 0 to infinity, is the default greedy match.

When coupled with the brackets, the brackets will content as unknown parameters passed to the back of view, it is necessary to add a parameter in the receiving function inside the test inside views.

Well-known groups:

有名分组
url(r'^test/(?P<month>\d+)/', views.test),
会将括号内匹配到的内容当做 关键字参数 传递给后面的视图函数test(request,month=123)

? P <> angle brackets inside alias write what is what, and will be passed to view functions as keyword arguments behind.

Anonymous and can not be used in conjunction with well-known, but the unknown and famous can themselves be used multiple times.

Guess you like

Origin www.cnblogs.com/chanyuli/p/11723470.html
Recommended