Ticket #2378 (closed defect: fixed)
General content_type ticket.
| Reported by: | jorge.vargas | Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | 2.1a2 |
| Component: | TurboGears | Version: | trunk |
| Severity: | normal | Keywords: | |
| Cc: |
Description
This is a catchall titcket for #2158 and #2280 as each solution breaks it the other way.
#2280 explains that @expose(content_type="foo/bar') should be the "default way" of doing this. This is the current behavior in both 2.0.x and 2.1.x.
However #2263 raises the issue of modifying the content type "at runtime" in the case the pylons way of doing it does not work therefore we are using a flag (CUSTOM_CONTENT_TYPE) to prevent it being overwritten. The underlying problem regarding this is under investigation, but it appears to be a trashing of the response object, therefore the correct code:
@expose()
def stats(self):
pylons.request['Content-Type'] = 'text/csv'
return '1,2,3'
Does not work with 2.x and the corresponding must be used:
@expose(content_type=CUSTOM_CONTENT_TYPE)
def stats(self):
pylons.request['Content-Type'] = 'text/csv'
return '1,2,3'
Change History
comment:3 Changed 3 years ago by ondrejj
None of them works for me. This is not accepted:
pylons.request['Content-Type'] = 'text/xml'
error:
TypeError: 'Request' object does not support item assignment
Versions: python-pylons-0.9.7-2.fc12.noarch TurboGears2-2.0.3-3.fc12.noarch
Any other ideas, how to change content-type on TG 2.0?
This has been fixed in TG2.1. Feel free to backport, here is the changeset. http://bitbucket.org/turbogears/tg-dev/changeset/436b239ac4ab/