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 #7 (closed defect: fixed)

Opened 14 years ago

Last modified 12 years ago

Be able to specify a content-type via expose

Reported by: kevin Owned by: anonymous
Priority: normal Milestone: 0.9a5
Component: TurboGears Version:
Severity: normal Keywords:
Cc:

Description (last modified by kevin) (diff)

As of right now, you can only explicitly expose a template for html rendering. The addition of the tg_format parameter allows you to say "I want json output by default" or "I want xml by default". It's that second one that bothers me, because you likely want a different content-type as well.

If people aren't particular about being able to return multiple types from a single method based on the browser's request (either ?tg_format or the Accept: header) as a general rule, then the cleanest thing to do is change "html" in expose to be "template" and add a content-type parameter. (I don't mind leaving html in there for backward compatibilty and people who like the comfort in knowing that they're sending out html.)

JSON will remain an option whenever you return a dict, since it's essentially free and will be easily extendable soon. JSON, of course, would only be the default if you specify the format for expose.

So, to be clear, here is what it would look like to serve up rss

@turbogears.expose(template="foo.templates.rss", format="xml",
content_type="text/xml+rss")
def foo_rss(self):
   pass

Change History

comment:1 Changed 14 years ago by kevin

  • Description modified (diff)

comment:2 Changed 14 years ago by kevin

  • Status changed from new to assigned

comment:3 Changed 14 years ago by kevin

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

Finished in [28].

comment:4 Changed 13 years ago by anonymous

  • Status changed from closed to reopened
  • Resolution fixed deleted
  • Milestone changed from 0.8 to 0.9a5

I tried the @expose(content_type="image/png") decorator in my method that generates PNG's with PIL but TurboGears 0.9a4 still returned the "Content-Type: text/html" header.

I had to revert to using cherrypy.response.headerMapContent-Type?="image/png"

comment:5 Changed 13 years ago by kevin

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

the problem was specifically a content_type without a template. Fixed in [1287].

comment:6 Changed 13 years ago by anonymous

Confirmed ok :) thanks

Note: See TracTickets for help on using tickets.