Acquisition parameters in the request url

First, access to parameters according to request

Suppose request address is:

http://127.0.0.1:8020/books/?title= language

 Then routing the background configuration:

re_path('books/$', views.BookView.as_view(), name="books")

Title acquisition parameters view through the request:

title = request.Get.get('title','')

Second, the acquisition parameters or by args kwargs

  • kwargs get the value

The requested address is:

http://127.0.0.1:8020/books/yuwen/

But routing the background parameter groups:

re_path('books/(?P<title>\w+)/$', views.BookView.as_view(), name="books"),

At this point you can get the parameters title by kwargs:

title = kwargs["title"]

args is empty in this case ancestral, but is worth kwargs dictionary { 'title': 'yuwen'}

  • Gets the value of args

Requested address is:

http://127.0.0.1:8020/books/yuwen/

But the route is not the packet:

re_path('books/(\w+)/$', views.BookView.as_view(), name="books"),

In this case the parameter values ​​of the title may be obtained by args:

title = args[0]

args this case is ( 'yuwen',), and the empty kwargs

Guess you like

Origin www.cnblogs.com/shenjianping/p/11517624.html