Reputation: 7134
Shall I use (and why?):
if request.POST
or:
if request.method == 'POST'
Is there any differences except syntax?
Upvotes: 7
Views: 1067
Reputation: 165182
If you want to check the request method, use if request.method == 'POST'
.
request.POST
is the post param dict, and you shouldn't count on its existence or lack thereof when it comes to the request method. (e.g. a post request with no params fails on that test.)
Explicit is better than implicit. -- PEP 20, Zen of Python
Upvotes: 9