Questions tagged [mako]

Mako is a template library written in Python. It provides a familiar, non-XML syntax which compiles into Python modules for maximum performance. Conceptually, Mako is an embedded Python (i.e. Python Server Page) language.

Mako is a template library written in Python. It provides a familiar, non-XML syntax which compiles into Python modules for maximum performance. Mako's syntax and API borrows from the best ideas of many others, including Django templates, Cheetah, Myghty, and Genshi. Conceptually, Mako is an embedded Python (i.e. Python Server Page) language, which refines the familiar ideas of componentized layout and inheritance to produce one of the most straightforward and flexible models available, while also maintaining close ties to Python calling and scoping semantics.

Mako is used by the python.org website as well as reddit.com. It is the default template language included with the Pylons web framework.

422 questions
4
votes
2 answers

Pyramid setting mako.imports not working

I'm trying to use the mako.imports setting to avoid importing modules in every template file. Originally I had a module-level block at the top of every template like: <%! import logging %> And I'd like to replace that with a setting in the .ini…
Hollister
  • 3,758
  • 2
  • 20
  • 22
4
votes
1 answer

How to set up mako templates with Flask to yield decipherable exceptions?

I like mako and wish it were easier to integrate with the Flask framework. I setup the flask-mako extension but quickly discovered that instead of the very nice flask debugger screen producing an easily understood traceback like it did with jinja, I…
chrickso
  • 2,994
  • 5
  • 30
  • 53
3
votes
1 answer

why an undefined variable is larger than a number in mako template?

I use a variable called x,the x is not defined, and use x to compare with a number in mako template: %if x>5:

helloworld

%endif And why this sentence not cause an exception or an error? But when I want to print this out: %if x>5: …
yudun1989
  • 996
  • 9
  • 23
3
votes
1 answer

How to make sure a script runs once and only once

I am writing a widget template, which will be included in a page where it is installed. One may install several of the same kind of widget in one page, so my template may get included several times. Now I have written some JavaScript to initialize…
satoru
  • 31,822
  • 31
  • 91
  • 141
3
votes
1 answer

Mako, Babel and string interpolation

I'm trying to do something like this: ${_('Hello ${name}, welcome to...', mapping=dict(name='${name}'))} Where _() is my Babel translation function, the first ${name} is string interpolation I'd like to be performed by Babel and the second ${name}…
ryonlife
  • 6,563
  • 14
  • 51
  • 64
3
votes
2 answers

404 error handling with mako template

Trying to display template rendered by mako on 404 errors, but it still displays standart error page with cherrypy footer and additional message: |In addition, the custom error page failed: TypeError: render_body() takes exactly 1 argument (3…
Zhlobopotam
  • 173
  • 13
3
votes
1 answer

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,…
Milimetric
  • 13,411
  • 4
  • 44
  • 56
3
votes
1 answer

Pyramid can not access static asset (neither an .jpg image nor a .js file)

I have a bigger testcase which uses Pyramid and Mako and also Javascript. It works fine unless I put the Javascript code into a separate file. Then it fails. I have reduced the test case to the following (3 files) replacing the JS file with a…
vnick
  • 31
  • 2
3
votes
1 answer

Using Webhelpers in mako template in Pyramid

How do I use Webhelpers in a Mako template in my Pyramid app? In Pylons I had global helper variable h to use in my templates so I could simply do: ${h.stylesheet_link("/css/default.css")} given I import stylesheet_link from webhelpers.html.tags…
neurino
  • 11,500
  • 2
  • 40
  • 63
3
votes
2 answers

variable substitution conflict between mako and Openlayers

I am using mako templates in pyramid which uses the ${} construct for variable substitution. I also use an Openlayers script to show a map with features. I want to style my features with Stylemap like so: var symbolizer =…
Adrian
  • 33
  • 3
3
votes
2 answers

Is there any way to pass all variables in the current scope to Mako as a context?

I have a method like so: def index(self): title = "test" return render("index.html", title=title) Where render is a function that automatically renders the given template file with the rest of the variables passed in as it's context. In…
Vlad the Impala
  • 15,572
  • 16
  • 81
  • 124
3
votes
0 answers

How to generate C code from Python?

I am writing an embedded algorithm. Currently I have lookup tables that are hard-coded: static const int32_t sine[65536] = { ... } The algorithm should be portable on different platforms but, the lookup table length changes depending on the…
nowox
  • 25,978
  • 39
  • 143
  • 293
3
votes
2 answers

UnicodeEncodeError in Mako Template

I have the following files dummy.py #!c:/Python27/python.exe -u from mako import exceptions from mako.template import Template print "Content-type: text/html" print #VARIABLE = "WE" VARIABLE = "我们" template =…
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
3
votes
6 answers

Is there a reason I should be dissuaded from using an alternative templating engine in my Django app?

I've done a few small-ish Django projects, and each time I've been struck by the apparent limitations of Django's templating language. Just as a random example, I was shocked to learn that if, in the context of a template, I had a variable bar and a…
Coquelicot
  • 8,775
  • 6
  • 33
  • 37
3
votes
1 answer

Pass in variable to Mako template

In Perl, by using Template Toolkit, here is what I do Perl my $vars = { name => 'Count Edward van Halen', }; $tt->process('letters/overdrawn', $vars) || die $tt->error(), "\n"; HTML Dear [% name %], In Mako template, how can I do so?…
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875