Capturing URL parameters in request.GET

后端 未结 13 1125
说谎
说谎 2020-11-22 08:30

I am currently defining regular expressions in order to capture parameters in a URL, as described in the tutorial. How do I access parameters from the URL as part the

13条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 09:06

    These queries are currently done in two ways. If you want to access the query parameters (GET) you can query the following:

    http://myserver:port/resource/?status=1
    
    request.query_params.get('status', None) => 1
    

    If you want to access the parameters passed by POST, you need to access this way:

    request.data.get('role', None)
    

    Accessing the dictionary (QueryDict) with 'get()', you can set a default value. In the cases above, if 'status' or 'role' are not informed, the values ​​are None.

提交回复
热议问题