Hi everybody, sorry, my last email was premature. I've gotten it to work like this:
from pyramid.renderers import render render("proj:templates/email/_event.html", context, request=request) So manually providing the asset-specification 'proj:templates' again seems to do the trick. Am Dienstag, 7. Juli 2015 20:10:39 UTC+2 schrieb Martin Stein: > > Hi all, > > in our current project we are using jinja with the pyramid_jinja2-package > and have defined the search-path in __init__.py as usual: > > config.add_jinja2_search_path('proj:templates', name='.html') > > Now I need to use that renderer/jinja-environment to render a > file-template to a string (not as a response). The documentation at > http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/templates.html#using-templates-directly > > says to do it like this: > > from pyramid.renderers import render > render("email/_event.html", context, request=request) > > But I get the strong impression that render(..) is broken when a > search-path is configured for pyramid_jinja2, because it inserts the > current package (e.g. 'proj:util') into the lookup-path: > > OSError: [Errno 22] Invalid argument: > 'PATH_TO_OUR_PROJECT\\proj\\proj\\templates\\proj.util:templates\\email\\_event.html' > > As a workaround, I could probably try to access the jinja2-environment > directly, similar to here: > http://stackoverflow.com/a/15539751 > > from pyramid_jinja2 import IJinja2Environment > env = request.registry.queryUtility(IJinja2Environment, name='.html') > > But as Michael writes, this is unsupported and a private API. > > So, that leads me to two questions: > 1) Has anybody gotten the template-lookup in render(..) to work when a > search_path was configured? How? > > 2) Alternatively, is there another option to get to the jinja-environment > besides: > env = request.registry.queryUtility(IJinja2Environment, name='.html') > > Thanks, > Martin > > > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.