7

Shall I use (and why?):

if request.POST

or:

if request.method == 'POST'

Is there any differences except syntax?

Mateusz Jagiełło
  • 6,854
  • 12
  • 40
  • 46

1 Answers1

9

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

Yuval Adam
  • 161,610
  • 92
  • 305
  • 395