On Apr 23, 3:53 pm, Juan Pablo Scaletti <[email protected]>
wrote:
> I don't think a decorator is the best solution.
> For instance, many times the HTML version needs a more data and
> processing than others (because it must render a header, sidebar,
> etc.)
That's true. I did it while implementing a webservice that could also
return html in some cases, not a proper web site.
>
> Something like this would be more flexible IMHO:
>
> def GET(self, arg1, arg2, ...):
> ... code to retrieve the data ...
>
> if json_requested():
> return json(data)
> elif txt_requested():
> return txt(data)
>
> ... more processing ...
> ... normal html rendering ...
Still, I don't see how this is more flexible. Your "...more
processing..." block could be inside the 'render_html' function
anyway.
Moreover, the whole if..elif thing is kind of rigid. There are cases
where more than one of the ?_requested() functions would return true.
For instance, a browser's typical Accept header allows html, xhtml,
plain text, xml or anything else, but with different priorities. With
your approach, you would end up returning the first (and not
necessarily the best) condition met.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" 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/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---