[Answered ]-What is the difference between request.POST.get and request.POST

1👍

request.POST is a dict-like object.

For dicts 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.

0👍

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

Leave a comment