Humberto Diógenes wrote:

> Thanks, Alberto. But as I said, I'm trying to port an old application
> -- that means I would have to add one request.GET line for every
> parameter in every controller function (and then remove all parameters
> from the function signature).
>
> I could do that, but what I'd really like to know is this: does Pylons
> support query string "parameter injection"? If not, how difficult
> would it be to implement that?

This past weekend, I participated in a sprint on Pylons where
we implemented two new controllers: DecoratedController and
ObjectDispatchController.  Both of these controllers perform "parameter
injection."  Here is an example of a DecoratedController:

     from pylons.controllers import DecoratedController
     from pylons.decorators import expose

     class TestController(DecoratedController):

         @expose()
         def testing(self, name):
             return 'Hello, %s' % name

Navigating your browser to '/test/testing?name=Humberto' will render the
string "Hello, Humberto."  You can also render templates from Buffet
compatible engines by passing specific information into the expose
decorator, like so:

     @expose('myproject.templates.testing')
     def testing(self, name):
         return dict(name=name)

The dictionary you return in the controller method will be used as the
namespace for your template.  You can also render JSON by simply doing
@expose('json').  The expose decorator can be stacked:

     @expose('json', content_type='application/json')
     @expose('myproject.templates.testing', content_type='text/html')
     def testing(self, name):
         return dict(name=name)

You then send the `Accept:` header to perform content negotiation to
determine which output will be rendered.

This is all very new, so it probably has some bugs, but please do give
it a try, and we'll do our best to fix any bugs you find!

--
Jonathan LaCour
http://cleverdevil.org


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to