Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Open
skorokithakis opened this Issue · 2 comments

3 participants

@skorokithakis

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

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

@chrislawlor

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

https://github.com/mitsuhiko/jinja2/blob/master/jinja2/loaders.py#L366

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

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.