Implement jinja's ModuleLoader #101

Closed
ghost opened this Issue Aug 3, 2010 · 4 comments

3 participants

@ghost

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

@dinoboff

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

#!/usr/bin/python2.5
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
    dev_appserver.fix_sys_path()
    compile_template("./compiled_templates.zip")

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()
        else:
            return ModuleLoader('compiled_templates.zip')


app = GAEFlask('myapp')
app.config.from_object('myapp.settings')
@jeffwidman
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?

@jeffwidman
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...

@untitaker
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