Search code examples
google-app-enginemako

Mako with Google App Engine - What do you do about temporary files?


I modified my Google App Engine app to work with Mako. To do this, I followed this answer including the comments:

Mako templates with Google App Engine

However, once you get to loading templates from files, you run into a big problem. By default, Mako's Template from mako/template.py wants to create a temporary file to store your compiled template. As far as I can tell, GAE doesn't allow you to create a temp file though. Has anyone run into this and figured out a work-around?


Solution

  • The awesome team that wrote the aha framework actually figured this out. The mako_patch function here makes Mako store temporary files in memcache instead of on the filesystem: http://code.google.com/p/aha-gae/source/browse/aha/controller/makocontroller.py

    EDIT: as @Nick Johnson points out, storing this in local memory would make just as much sense and not incur the cost of memcache.