Capturing URL parameters in request.GET

后端 未结 13 834
说谎
说谎 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 08:57

    If you only have access to the view object, then you can get the parameters defined in the URL path this way:

    view.kwargs.get('url_param')
    

    If you only have access to the request object, use the following:

    request.resolver_match.kwargs.get('url_param')
    

    Tested on Django 3.

提交回复
热议问题