Jinja caches templates by filename, not by full path. #15

skorokithakis opened this Issue Feb 7, 2011 · 2 comments


None yet
4 participants

Apparently Jinja uses the template filename in the cache instead of the full pathname. This leads to "index.html", for example, returning the wrong thing if the template loader path has been changed.

If Jinja caches by the whole path (which makes sense, since you're trying to load a specific template), this will work correctly.

Trii commented Mar 8, 2013

Was this issue ever solved? I have the same issue while trying to implement themes with the FileSystemLoader. In my use case, a theme may override a default template but does not need to so my files must be named the same but live in different paths. The paths change per request so a cached home.html in /theme1/ might be valid for User 1 but User 2 should see /theme2/home.html

This issue thread is pretty old, but in case someone is looking for a solution, it looks like 'ChoiceLoader' addresses this use case:


class ChoiceLoader(BaseLoader):
    """This loader works like the `PrefixLoader` just that no prefix is
    specified.  If a template could not be found by one loader the next one
    is tried.

    >>> loader = ChoiceLoader([
    ...     FileSystemLoader('/path/to/user/templates'),
    ...     FileSystemLoader('/path/to/system/templates')
    ... ])

    This is useful if you want to allow users to override builtin templates
    from a different location.

Documented here: http://jinja.pocoo.org/docs/api/#jinja2.ChoiceLoader

mitsuhiko closed this Jan 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment