Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

list_templates doesn't take a list of extensions #306

Closed
bengolder opened this Issue · 2 comments

3 participants

@bengolder

I'm new to jinja, and I encountered a discrepancy between the documentation and behavior. Perhaps this is intentional, but I found it confusing.

from the docs for Environment.list_templates():

Returns a list of templates for this environment [...] extensions is set to a list of file extensions for templates [...]

If you feed a list of file extensions to list_templates() you get an itertools.ifilter object, not a list. But this doesn't seem to "yield" the right results (pun intended).

loader = jinja2.FileSystemLoader('templates')
env = jinja2.Environment( loader=loader )
use results
print env.list_templates() ['css/mapstyle.css', 'js/map.js', 'map_template.html']
print env.list_templates(['.html', '.css']) <itertools.ifilter object at 0x10baa9350>
print env.list_templates('.html') <itertools.ifilter object at 0x10baa9310>
print list(env.list_templates(['.html'])) []
print list(env.list_templates('.html')) ['map_template.html']
print env.list_templates(extensions=['.html']) <itertools.ifilter object at 0x10ba92090>
print [n for n in env.list_templates('.html')] ['map_template.html']
print [n for n in env.list_templates(['.css','.html'])] []
@mitsuhiko
Owner

This was a regression from the python 3 port. Fixed.

@mitsuhiko mitsuhiko closed this
@mbehrle

It just took me quite a while to get the right format to call the extension argument. Not knowing which is the expected bahavior I am reopening, because either documentation or behavior could be improved.

Providing a list of extensions (as understood as a python list) just returns an empty list:
extensions=['html', 'jinja'] => result []
while a string of comma separated list of extensions works as expected:
extensions='.html,.jinja' => works as expected

Thanks for jinja2!

@mbehrle mbehrle referenced this issue from a commit in mbehrle/nereid
@mbehrle mbehrle Use extension argument of list_templates.
- Setting filter to only include .html and .jinja.
- Caveat: mitsuhiko/jinja2#306
0646c75
@mbehrle mbehrle referenced this issue from a commit in mbehrle/nereid
@mbehrle mbehrle Use extension argument of list_templates to filter templates (gh#74).
 - Setting filter to only include .html and .jinja.
 - Caveat: mitsuhiko/jinja2#306
38f194f
@sharoonthomas sharoonthomas referenced this issue from a commit in openlabs/nereid
@mbehrle mbehrle Take only files ending on .jinja/.html as template
 - Use extension argument of list_templates to filter templates
 - Setting filter to only include .html and .jinja.
 - Caveat: mitsuhiko/jinja2#306
 - Also refer: openlabs/nereid-webshop#74
be523e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.