Compiled Templates With Macros Do Not Work On App Engine
I use Jinja2 compiled templates and a module loader to load the compiled templates (python code) from the datastore. But when my template contains a macro it does not work on app e
Solution 1:
I was able to solve it, by adding the module to the sys.modules. But I do not understand why it worked in the SDK and not in GAE when I use a macro
Here is the code of my changed module loader.
defget_module(self, environment, template):
# Convert the path to a module name
name = template.replace('.html', '').replace('.txt','').replace('/', '.') # NO extensions
module = Noneif self.package == None : # load from db and not from package
logging.info('load module : ' + name) # load module from runtimes db if name in sys.modules : return sys.modules[name] # already imported try :
runtime = models.Runtimes.rtimes_get_by_key_name(template)
module_code = db.Text(runtime.compiled)
module = imp.new_module(name)
exec module_code in module.__dict__
sys.modules[name] = module # add to sys modules, so no import againreturn module
except (ImportError, AttributeError):
logging.error('load failed : ' + name)
else : .... # load from packageraise TemplateNotFound(template)
Post a Comment for "Compiled Templates With Macros Do Not Work On App Engine"