Opened 13 years ago
Last modified 13 years ago
#16398 closed New feature
HttpResponse object should return self when write() method is called — at Version 4
Reported by: | Jonathan Sawyer | Owned by: | nobody |
---|---|---|---|
Component: | HTTP handling | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
My use case:
# Current procedure def myview(req): resp = HttpResponse(mimetype='application/javascript') resp.write(json.dumps({'msg': 'Hello World!'})) return resp # Desired procedure def myview(req): resp = HttpResponse(mimetype='application/javascript') return resp.write(json.dumps({'msg': 'Hello World!'}))
HttpResponse.write()
returns None initially. It would be really nice if .write() would return self so I can return an HttpResponse
object. Instead I have to take up an extra line of code (and in my application, that is a lot when duplicated).
An extension on this request could be that all public methods on HttpResponse
should return self.
Change History (4)
by , 13 years ago
Attachment: | 16398.patch added |
---|
comment:1 by , 13 years ago
Attached is my patch. I have tested this functionality and it works when objects use HttpResponse as file objects. As far as I know, this won't break python compatibility because on errors, exceptions are raised rather than the output being the form of an error code. Thanks in advance.
comment:3 by , 13 years ago
Has patch: | set |
---|
comment:4 by , 13 years ago
Description: | modified (diff) |
---|
Patch to #16389 where self is returned on .write() method