Mateusz Jagiełło
Mateusz Jagiełło

Reputation: 7134

Django - request POST

Shall I use (and why?):

if request.POST

or:

if request.method == 'POST'

Is there any differences except syntax?

Upvotes: 7

Views: 1067

Answers (1)

Yuval Adam
Yuval Adam

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

Related Questions