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
8
votes
1 answer

Formatting a date with Mako templates

In my mako template I have:

${item.addDate}

It returns: 2012-12-27 19:50:00 but I would like to get: 27/12/2012 19:50 Have mako any nifty filters, format functions?
David Silva
  • 1,939
  • 7
  • 28
  • 60
7
votes
2 answers

Some questions regarding Mako modules, Mako's TemplateLookup function, and Pyramid

I'm looking at Mako's documentation and I found a TemplateLookup function for Mako: Using TemplateLookup. However, I've never seen this in Pyramid's documentation since I've never had to specify a modules directory. My questions are: What "modules"…
Jonathan Ong
  • 19,927
  • 17
  • 79
  • 118
7
votes
5 answers

Strip whitespace from Mako template output (Pylons)

I'm using Mako + Pylons and I've noticed a horrendous amount of whitespace in my HTML output. How would I go about getting rid of it? Reddit manage to do it.
Matthew H
  • 5,831
  • 8
  • 47
  • 82
7
votes
4 answers

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 537: ordinal not in range(128), referer: ... I always get this error when I try to output my whole website with characters "č". I am using mako templating. What to do?
Haris Bašić
  • 1,383
  • 2
  • 12
  • 21
7
votes
5 answers

Should I use Mako for Templating?

I've been considering a templating solution, although my choices are between Mako and Genshi. I find templating in Genshi a bit ugly, so I'm shifting more towards Mako. I've gone to wonder: what is so good about the fact that Mako allows embedded…
Pyornide
7
votes
3 answers

pylons mako how to check if variable exist or not

In django, we can do this: views.py : def A(request): context = {test : 'test'} return render_to_response('index.html', context , context_instance = RequestContext(request)) def B(request): context = {} …
Santana
  • 177
  • 3
  • 9
6
votes
1 answer

Choose Mako preprocessor based on file extension?

I would like to somehow instrument a mako.lookup.TemplateLookup such that it applies certain preprocessors only for certain file extensions. Specifically, I have a haml.preprocessor that I would like to apply to all templates whose file name ends…
Mike Boers
  • 6,665
  • 3
  • 31
  • 40
6
votes
0 answers

A scheme for file type extensions for Mako templates in PyCharm

In our company, we use Mako templates to generate a lot of files: HTML, XML, TXT, CSV... However, it seems it's not easy to configure PyCharm to recognize the file types with embedded Python correctly. As a result, PyCharm is not able to highlight…
peter.slizik
  • 2,015
  • 1
  • 17
  • 29
6
votes
1 answer

Dictionary literals in Mako expressions

The following throws a syntax error, "unexpected EOF while parsing": ${foo({'bar':'baz'})} which I guess is from the inner closing curly brace. This works fine: ${foo(dict(bar='baz'))} but what's the syntax for using a dictionary literal?
Hollister
  • 3,758
  • 2
  • 20
  • 22
6
votes
2 answers

How can I connect my python script with my HTML file?

Basically I am getting some data from a webpage, and putting it into an array, I want to output the contents of that array into a table in a HTML file. After some research I found that using a mako template might be the best solution, but I don't…
bkhmsi
  • 61
  • 1
  • 1
  • 3
6
votes
2 answers

Mako escaping issue within Pyramid

I need to put javascript function to mako template. The first argument of this function is string, so I write in my *.mako file (dict(field_name='geom')): init_map( '${field_name}' ); But when I see my html page it loks like: init_map( …
drnextgis
  • 2,194
  • 1
  • 25
  • 32
6
votes
2 answers

Output all variables into Mako template

I don't have an easy access to the code, I'm working only with a Mako template, and I would like to know all the values that were made available to the template, which I can use. Is there a way to add something in the template, so that the output…
Jānis Elmeris
  • 1,975
  • 1
  • 25
  • 43
5
votes
1 answer

How to check for authenticated user in Pyramid templates?

I am using Pyramid 1.3b with Mako templating. I have a base template that displays some navigational components based on whether the user is logged-in or not. I am doing it this way: <%! from pyramid.security import…
Mark
  • 2,137
  • 4
  • 27
  • 42
5
votes
1 answer

How can I handle NameError and AttributeError gracefully in the Mako runtime environment?

I've found that trying to access an undefined variable within a Mako template raises a NameError, and quite logically so. In some applications, however, it's desirable to fail more gracefully, perhaps substituting the empty string on such errors…
David Eyk
  • 12,171
  • 11
  • 63
  • 103
5
votes
1 answer

Problem with IF statement in mako template

I have mako template where i check conditions from a simple dict in for loop, like: % for el in seq: % if el["attr"] == 1: ... elif: .... else: ..... % endif And if i want add another IF statement in this…
Denis
  • 7,127
  • 8
  • 37
  • 58
1
2
3
28 29