On Tue, Jun 28, 2011 at 1:52 PM, Liju <lij...@gmail.com> wrote:

> But was checking if there was a way to invoke a template
> directly without having to route request to a view, like JSP (in
> J2EE).
>
> But I guess its not worth it.
>
> On Jun 28, 11:27 am, Michael Merickel <mmeri...@gmail.com> wrote:
> > All of Pyramid's template rendering is handled in the context of a
> request.
> > This is primarily because the template lookup is handled through the
> > registry which is attached to the request. If you have the registry, you
> can
> > use pyramid.renderers.render() with a dummy request object in order to
> use
> > the template directly (or if you are in a view, you may just pass in your
> > current request object).
>

You specifically asked how to render a template based on a request
parameter, which implies that you have a request, which implies that we have
no problem here.

Like I said, you can fake a request fairly easily, but if you want to use
the templating engines that pyramid set up for you, they require the
registry.

Assuming that the registry is in pyramid.threadlocal.get_current_registry()
correctly, you can simply call render('mytemplate.mako', { some dict of
values }) and it will work without a request.

FWIW if you truly don't care about doing anything in python, you can of
course define a view that doesn't do anything, and register that for the
routes you want to render:

    def null_view(request):
        pass

    config.add_route('my_route', '/')
    config.add_route('my_users', '/users')

    config.add_view(null_view, route_name='my_route',
renderer='mytemplate.mako')
    config.add_view(null_view, route_name='my_users',
renderer='myusers.mako')

-- 

Michael

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to