On 6/24/07, Jonathan LaCour <[EMAIL PROTECTED]> wrote:
>
> Jorge Vargas wrote:
>
> > that seems nice. It will be interesting I'll like to see how this will
> > be "configure", to handle the multiple templating engines for the
> > different file types.
>
> It will basically work like this:
>
>      class PersonController(TurboGearsController):
>
>          @expose('json', content_type='application/json')
>          @expose('templates.person', content_type='text/html')
>          def person(self, id):
>              person = Person.get(id)
>
>              return dict(
>                  name=person.name,
>                  age=person.age,
>                  address=person.address
>              )
>
> Now, when you want to fetch an HTML representation of the person with ID
>
> number 1, you could do it in two ways:
>
>      1. Fetch '/person/1' passing the 'Accept: text/html' HTTP header.
>      2. Fetch '/person/1.html'
>
> If you want to fetch a JSON representation of the person with ID number
> 1, you could do it in two ways as well:
>
>      1. Fetch '/person/1' passing the 'Accept: application/json' HTTP
>         header.
>      2. Fetch '/person/1.json'
>
> This way, you can do content-negotiation the "right" way if you have
> the ability to send HTTP headers, but can still link to a particular
> representation when needed.
>
> In the case of @expose('json'), we default content_type to
> 'application/json', and in the case of @expose('template...'), we
> default the content_type to 'text/html' for convenience.
>
that all sounds really nice I like the headers part for non-browser
clients. Looking forward for this :)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to