1

Pyramid offers a beforeRenderer

    from repoze.events import subscriber
    from pyramid.events import BeforeRender

    @subscriber(BeforeRender)
    def add_global(event):
        print event['renderer_name']      #this is the renderer name
        print event['renderer_info'].name #same with event['renderer_name']

But not useful. If I change or delete the event['renderer_name'] and event['renderer_info'].name, it can also find the renderer(a template file) in config.

    config.add_view('mywork.views.index.index',
                     route_name='/index',
                     renderer='mywork:templates/index.pt')

I want use the renderer's name in view.py or in root_factory to change the renderer value, so it can change all templates.

1 Answers1

1

BeforeRender is called before rendering. In other words, it's called after view.py where I assume you placed your view. root_factory is also called much before that. root_factory is used to create the root node for traversal. This is what will return a context. Without context, your view doesn't get called and pyramid raise a context not found error.

BeforeRender is called after your view returned some parameters or possibly before calling renderToResponse which return a renderer response. You there can pass a renderer from within your view.

http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/templates.html#using-templates-directly

And you have to remove the renderer parameter when you set your view.

Loïc Faure-Lacroix
  • 13,220
  • 6
  • 67
  • 99