Dynamic content from actions

In the previous post (blog:dynamic_images) we saw how to use the action() method of the img tag to put dynamic images in a view.

Let's see now how to serve any other dynamic content by raising a HTTPOk exception:

import time
from webob.exc import HTTPOk
class MyApp(object):
    def get_text(self, *args):
        data = time.asctime()
        e = HTTPOk()
        e.body = data
        e.content_type = 'text/plain'
        raise e
from nagare import presentation
@presentation.render_for(MyApp)
def render(self, h, *args):
    return h.a('Click me').action(self.get_text)

Nagare catches such webob.exc exceptions; as they inherit from webob.Response they are immediatly returned in the WSGI pipe.

Comments

No comments.