Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我应该使用(为什么?):
if request.POST
或者:
if request.method == 'POST'
除了语法有什么不同吗?
如果要检查请求方法,请使用if request.method == 'POST'.
request.POST是 post param dict,当涉及到请求方法时,你不应该指望它的存在或缺乏。(例如,没有参数的发布请求在该测试中失败。)
request.POST
显式优于隐式。-- PEP 20,Python 之禅