usually I use POST or GET requests except for GET.get paginations, but I don't understand the concept there are only two possibilities POST or GET .
example even if there is the same effect I do not understand the difference between
request.GET.get('page') and request.GET["page"] request.POST['rate'] and request.POST.get('rate')
CodePudding user response:
request.POST
is a dict
-like object.
For dict
s and their derivatives, d[x]
equates to indexing into the dict
by key x
, and d.get(x, default)
is a method that is equivalent to indexing, except it returns a default value instead of throwing a KeyError
. If the default value is not set, d.get()
will return None.
CodePudding user response:
request.POST['sth']
will raise a KeyError exception if 'sth' is not in request.POST.
request.POST.get('sth')
will return None if 'sth' is not in request.POST