Created
October 26, 2011 08:04
-
-
Save Pitmairen/1315752 to your computer and use it in GitHub Desktop.
Flask template loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os.path | |
from jinja2 import FileSystemLoader, BaseLoader | |
from flask import session | |
class VersionedTemplatesLoader(BaseLoader): | |
def __init__(self, app): | |
base_template_path = os.path.join(app.root_path, 'templates') | |
self._old_templates = FileSystemLoader( | |
[os.path.join(base_template_path, 'v0')] | |
) | |
self._new_templates = FileSystemLoader( | |
[os.path.join(base_template_path, 'v1')] | |
) | |
def get_source(self, environment, template): | |
if session.get('use_new_templates', False): | |
return self._new_templates.get_source(environment, template) | |
return self._old_templates.get_source(environment, template) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment