Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2378 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

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:1 Changed 5 years ago by percious

  • Status changed from new to closed
  • Resolution set to fixed

This has been fixed in TG2.1. Feel free to backport, here is the changeset.  http://bitbucket.org/turbogears/tg-dev/changeset/436b239ac4ab/

comment:2 Changed 5 years ago by percious

  • Milestone changed from 2.* bugfix to 2.1a2

comment:3 Changed 5 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?

Note: See TracTickets for help on using tickets.