2

I want to use Mako templates with GAE instead of Django templates. I found this post http://blog.pansapiens.com/2008/06/24/mako-templates-in-google-app-engine-seems-to-work-for-me/

I downloaded Mako from this page by using easy_install http://www.makotemplates.org/download.html

But that gave me a "beaker" file

c:\python26\lib\site-packages\beaker-1.5.4-py2.6.egg

that I don't know what to do with.

Can someone help me so that I can get "Mako" file to put in my GAE directory as instructed in the blog.

I saw the reference to Mako/GAE here Google App Engine--Dynamically created templates

Thank you.

Community
  • 1
  • 1
Zeynel
  • 13,145
  • 31
  • 100
  • 145

1 Answers1

5

I use Mako on App Engine. It works very well for me.

All I do is download mako directly, then place the mako module directory in my app root.

Robert Kluin
  • 8,282
  • 25
  • 21
  • Thanks! I have the folder Mako-0.3.4. Is that the mako module? And what is the correct from-import language that I need to use in the script. Thanks again. – Zeynel Oct 15 '10 at 03:39
  • 2
    You want the `mako` folder that is inside the Mako-0.3.4 folder. Then you can use the command from the guide you found, `from mako.template import Template` and so on. – Robert Kluin Oct 15 '10 at 03:51
  • That gives an error: File "C:\Users\A\Desktop\hw2\mako\filters.py", line 11, in import markupsafe ImportError: No module named markupsafe – Zeynel Oct 15 '10 at 04:08
  • 2
    Sorry, forgot about that. Edit `filters.py`, change line 11 (`import markupsafe`) to `import cgi` then change line 25 (`return markupsafe.escape(string)`) to `return cgi.escape(string)`. – Robert Kluin Oct 15 '10 at 04:18
  • 1
    Or download also [MarkupSafe](http://pypi.python.org/pypi/MarkupSafe). You then don't need to alter Mako source code. – Ivo Danihelka Jan 01 '11 at 12:13
  • If you look at `setup.py` for mako, it clearly states that there is a dependency with `MarkupSafe`. – jldupont Mar 26 '11 at 18:09
  • Ah, ran into a pretty big problem here. Mako needs to create temporary files by default. It doesn't seem like there's a way to change template.py to allow it to do that, since Google App Engine doesn't make temporary files. Did you find a work-around for this? – Milimetric Aug 18 '11 at 20:52
  • 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 – Milimetric Aug 18 '11 at 21:19
  • @Milimetric I've never encountered an issue with that on App Engine. However, I've not updated mako in any projects for a few months though, so perhaps that is why. – Robert Kluin Aug 19 '11 at 04:43
  • @Robert Kluin, makes sense: I'm using 0.4.2 so maybe _compile_module_file is new to Mako. I haven't done any performance testing yet but I think compiling it to memcache should be great. I can't imagine having more than a few MB of template files altogether in my case. – Milimetric Aug 19 '11 at 15:18
  • I switched to django from Mako. Mako is great and I would've stayed with Mako unless I needed i18n with .po files and some less than most common tags. Mako is very readable but django has many more components. – Niklas Rosencrantz Aug 25 '11 at 20:28