Load jinja2 templates dynamically on a Pyramid view -


i'm developing pyramid project jinja2 templating engine. following jinja2 documentation i've find out way load different templates unique view. taking account module pyramid_jinja2 configured in app default path templates. wondering if there way more elegant done. approach:

from jinja2 import environment, packageloader  @view_config(context=test) def test_view(request):     env = environment(loader=packageloader('project_name', 'templates'))     template = env.get_template('section1/example1.jinja2')     return response(template.render(data={'a':1,'b':2})) 

can instance of pyramid_jinja2 environment somewhere don't have set again default path templates in view?

the following enough:

  pyramid.renderers import render    template = "section/example1.jinja2"   context = dict(a=1, b=2)   body = render(template, context, request=request) 

and configure loading in __init__.py:

  config.add_jinja2_search_path('project_name:templates', name='.jinja2', prepend=true) 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -