Opened 18 years ago
Closed 17 years ago
#3526 closed (fixed)
HttpResponse object should have 'content_type' argument (in additon to / instead of 'mimetype')
Reported by: | Simon Willison | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | httpresponse | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I can never remember the 'mimetype' argument to HttpResponse; I always have to look it up. The corresponding HTTP header is 'Content-Type'; I think that content_type would be a more memorable and more accurate argument.
For example:
return HttpResponse(simplejson.dumps({ 'airports': airports }), mimetype='application/json; charset=utf-8')
Should be:
return HttpResponse(simplejson.dumps({ 'airports': airports }), content_type='application/json; charset=utf-8')
The charset=utf-8 bit further demonstrates that mimetype should be renamed - charset=utf-8 is a parameter, not part of the actual mime media type.
I suggest adding content_type as an alternative to mimetype; I see no particular need to deprecate mimetype and break existing code, although it may be something that should be removed in the future.
Attachments (1)
Change History (10)
by , 18 years ago
Attachment: | content_type.diff added |
---|
comment:1 by , 18 years ago
Has patch: | set |
---|---|
Needs documentation: | set |
comment:2 by , 18 years ago
Needs tests: | set |
---|
comment:3 by , 18 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:4 by , 18 years ago
Triage Stage: | Design decision needed → Accepted |
---|
This looks reasonable. However, isn't the patch broken? If you pass in mimetype, but not content_type, then lines 162 and 163 will stomp all over line 161 in the new version. Looks like 163 should be "elif". Otherwise, looks like the right idea.
comment:6 by , 17 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:8 by , 17 years ago
The only change I made in the version I'm about to commit is to move the content_type parameter to the end of the constructor list to preserve backwards compatibility for people using positional arguments.
comment:9 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch to add content_type argument without breaking mimetype