Implement jinja's ModuleLoader #101

ghost opened this Issue Aug 3, 2010 · 4 comments

3 participants


It would be interesting to implement ModuleLoader in flask. It would make a huge difference in GAE response times for flask applications.


I think you would compile your template with the following script:

import sys

SDK_PATH = "/usr/local/google_appengine"

def logger(m, *args, **kw):
    print m

def compile_template(dest):
    from myapp import app
    app.debug = True
    app.jinja_env.compile_templates(dest, log_function=logger)

if __name__ == '__main__':
    sys.path.insert(0, SDK_PATH)
    import dev_appserver

And with flask 0.7, you would load the compiled template like that:

from flask import Flask
from jinja2 import ModuleLoader
import settings

class GAEFlask(Flask):

    def create_global_jinja_loader(self):
        if self.DEBUG:
            return super(GAEFlask, self).create_global_jinja_loader()
            return ModuleLoader('')

app = GAEFlask('myapp')
The Pallets Projects member

This is an ancient issue, and I'm not too familiar with Jinja2 internals. Anyone know if it's still relevant?

The Pallets Projects member

@untitaker looks like you started to mark as closing candidate but then thought better of it, I'm curious why? At this point, I'd just close it as an ancient issue with not enough traction...

The Pallets Projects member

@dinoboff showed how it is possible, but having ModuleLoader as a default is not very user friendly and usually not fixing the actual bottleneck.

@untitaker untitaker closed this Jun 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment