I've narrowed the issue down. The problem occurs when the template is 
located in a sub-directory of templates, but I'm guessing that the mistake 
is on my side. I've added an example here:
https://github.com/martinstein/pyramid_jinja_issue/tree/master/pyramid_jinja_issue

The relevant lines are:

@view_config(route_name='broken', renderer='email/mytemplate.html')
@view_config(route_name='works2', 
renderer='pyramid_jinja_issue:templates/email/mytemplate.html')
@view_config(route_name='works', renderer='mytemplate.html')
def my_view(request):
    return {"name": "Bruce"}

So the only question that remains is: How to specify the path to a 
template, when that template is located in a subdirectory of /templates?



Am Dienstag, 7. Juli 2015 21:37:44 UTC+2 schrieb Michael Merickel:
>
> Hmm, in theory it's supposed to fallback to the search path but try 
> the asset spec first. If you could add a reproducible example to an 
> issue I'd be happy to take a look. 
>
> On Tue, Jul 7, 2015 at 2:18 PM, Martin Stein <[email protected] 
> <javascript:>> wrote: 
> > 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 [email protected] <javascript:>. 
> > To post to this group, send email to [email protected] 
> <javascript:>. 
> > Visit this group at http://groups.google.com/group/pylons-discuss. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply via email to