How to get the parameters in request.GET and request.POST django

created at 07-17-2021 views: 1

This article mainly explains how to get the parameters in request.GET and request.POST

get parameters from request.GET

If you want the parameters corresponding to page in http://www.example.com/?page=2.

URLconf method

(r'^(?P<page>\w{0,50})/$', views.index_page,),

views.py

def index_page(request, page):
    pass

view function

def index_page(request, page=None):
    rn = request.GET.get('rn')

get parameters from request.POST

The first: can only be obtained in the view function

def index_page(request, page=None):
     rn = request.POST.get('rn')
     # Or as follows, note that if there is no such parameter, it will directly report KeyError
     rn = request.POST['rn']
Please log in to leave a comment.