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
5
votes
3 answers

WTForms - display property value instead of HTML field

I want to re-use a template I have with my WTForms form: ${form.name.label} ${form.name()} ... However, on my edit page, I want the input fields to display as normal (TextField, SelectField, etc.), while on my view page, I want to…
Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222
5
votes
2 answers

Best Practices for Python UnicodeDecodeError

I use Pylons framework, Mako template for a web based application. I wasn't really bother too deep into the way Python handles the unicode strings. I had tense moment when I did see my site crash when the page is rendered and later I came to know…
user90150
5
votes
1 answer

Mako templates using Django template tags

Our Django site is built using Mako templates. We want to use a third party project called django-socialregistration, but its template tags use Django's templates. If we used Django templates we could just {% load facebook_tags %} {%…
Dave Aaron Smith
  • 4,517
  • 32
  • 37
5
votes
1 answer

Why can't Mako locate a template beside the one that's including it?

Ok, running this in python: from mako.lookup import TemplateLookup from mako.template import Template mylookup = TemplateLookup(directories=['/home/user/webapps/app/www/templates/']) mytemplate =…
user713713
  • 607
  • 1
  • 8
  • 12
5
votes
2 answers

Mako Template Variable Names

Is it it possible to get the names of the variables in a Mako Template before rendering? from mako.template import Template bar = Template("${foo}") # something like: # >> print bar.fields() # ['foo'] Use case: We have configuration files whereby…
lycovian
  • 343
  • 1
  • 9
5
votes
2 answers

template lookup issues. What am i not understanding?

Background: I have the following directory structure: /absolute/path/to/templates components/ component1.mak component2.mak template1.mak The plan is for the templates in the template…
Sheena
  • 15,590
  • 14
  • 75
  • 113
5
votes
2 answers

How do I use a global variable in cherrypy?

I need to access a global variable that keeps its state over diffferent server requsts. In this example the global variable is r and it is incremented at each request. How can I make r global in cherrypy? import cherrypy import urllib class…
Mirko Cianfarani
  • 2,023
  • 1
  • 23
  • 39
5
votes
2 answers

Using from __future__ import in Mako template

I have <%! from __future__ import division %> at the very top of my template file. I get the error: SyntaxError: from __future__ imports must occur at the beginning of the file What's the correct way to do this?
Hollister
  • 3,758
  • 2
  • 20
  • 22
4
votes
1 answer

Mako: passing variables to base and child templates

Goal: To access myargs in both base and child templates. Currently I can only access them in one or the other. Call: child.render(myargs={'a':2, b:'5'}) Base excerpt: <%page args="myargs=None, **kwargs"/> % if myargs['a']: a is:…
user1012037
  • 501
  • 1
  • 4
  • 18
4
votes
1 answer

How to include CSS file in Mako?

I'm using Mako template for a project. How can I add a CSS file in Mako? I try to use in the tag, but it doesn't work.
4
votes
2 answers

Python functions in Mako templates (not in module-level blocks)

I'm using Pyramid and Mako for templating. It is possible to define a (semi-anonymous) function within a Mako block <% and %>. I know it can be done with a module-level block <%! and %>, but this means my function doesn't have any access to the…
axon
  • 688
  • 1
  • 7
  • 18
4
votes
4 answers

access variable declared in child template or controller-wide variables

I have a small hierarchy of mako templates that go something like: base.mako

${self.view()}

${listactions(self.mainactions)} ${self.body()} <%def name="listactions(actions)">
    % for action in actions: …
rhyek
  • 1,790
  • 1
  • 19
  • 23
4
votes
1 answer

Trimming Mako output

I really like the Mako templating system that's used in Pylons and a couple other Python frameworks, and my only complaint is how much WS leaks through even a simple inheritance scheme. Is there anyway to accomplish below, without creating such huge…
David
  • 17,673
  • 10
  • 68
  • 97
4
votes
2 answers

Calling a def as a function in a Mako template

I'd like to use a def as a function, and call it from an if block: <%def name="check(foo)"> % if len(foo.things) == 0: return False % else: % for thing in foo.things: % if thing.status == 'active': …
Hollister
  • 3,758
  • 2
  • 20
  • 22
4
votes
1 answer

How to use Pylons / Mako templates to make an HTML email from a stand alone python script?

I'm basically asking how to "include" the plyons and mako files in a stand alone python script? I have a working web site, but what I want to do is use Mako templetes to format emails that I initiate through a cron script. I want to do it this way…
Tom
  • 43
  • 3
1 2
3
28 29