Opened 13 years ago

Last modified 13 years ago

#16398 closed New feature

HttpResponse object should return self when write() method is called — at Initial Version

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

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 (1)

by Jonathan Sawyer, 13 years ago

Attachment: 16398.patch added

Patch to #16389 where self is returned on .write() method

Note: See TracTickets for help on using tickets.
Back to Top