Capturing URL parameters in request.GET

后端 未结 13 1028
说谎
说谎 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:58

    When a URL is like domain/search/?q=haha, you would use request.GET.get('q', '').

    q is the parameter you want, and '' is the default value if q isn't found.

    However, if you are instead just configuring your URLconf**, then your captures from the regex are passed to the function as arguments (or named arguments).

    Such as:

    (r'^user/(?P\w{0,50})/$', views.profile_page,),
    

    Then in your views.py you would have

    def profile_page(request, username):
        # Rest of the method
    

提交回复
热议问题