Opened 18 years ago
Closed 18 years ago
#2931 closed defect (fixed)
"if request.POST" should read "if request.method == 'POST'"
Reported by: | Owned by: | Jacob | |
---|---|---|---|
Component: | Documentation | Version: | |
Severity: | minor | Keywords: | |
Cc: | gary.wilson@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
From http://www.djangoproject.com/documentation/request_response/#httprequest-objects
we have:
It's possible that a request can come in via POST with an empty POST dictionary -- if, say, a form is requested via the POST HTTP method but does not include form data. Therefore, you shouldn't use if request.POST
to check for use of the POST method; instead, use if request.method == "POST"
(see above).
Then in http://www.djangoproject.com/documentation/forms/
we violate that advice with:
def create_place(request): manipulator = Place.AddManipulator() if request.POST: ...
Change History (6)
comment:1 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 18 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
request.POST
is used once elsewhere in the docs and several places in trunk too that maybe should be changed.
comment:3 by , 18 years ago
Cc: | added |
---|
comment:4 by , 18 years ago
Hmm, should that be request.method.lower() == 'post'
to be really sure? Just nitpicking, though.
comment:5 by , 18 years ago
.lower()
shouldn't be necessary: according to documentation, request.method
will always return an uppercase value.
comment:6 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
(In [3914]) Fixed #2931 -- Use request.method == 'POST' where appropriate in the examples.
Thanks, David Schein.