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

Python / Mako : How to get unicode strings/characters parsed correctly?

I'm trying to get Mako render some string with unicode characters : tempLook=TemplateLookup(..., default_filters=[], input_encoding='utf8',output_encoding='utf-8', encoding_errors='replace') ... print…
felace
  • 993
  • 1
  • 12
  • 21
3
votes
2 answers

How do I get some string values from Pylons controller be assigned to JavaScript variables with Mako?

I'm developing under Pylons using Mako templates. The problem is that I need to assign a string from some attribute of tmpl_context to a JavaScript variable in a page body. The additional problem is that this string can be quite arbitrary, ie can…
eigenein
  • 2,083
  • 3
  • 25
  • 43
3
votes
2 answers

Python Django migrate_schemas --shared TypeError: hasattr(): attribute name must be string upon

I am trying to create a python django-mako-plus project with a django-tenant-schema. I followed the instructions exactly as the tutorial here: https://django-tenant-schemas.readthedocs.org/en/latest/install.html#basic-settings However, when I run…
3
votes
1 answer

Remove leading whitespace in Mako template

In a use case for autogenerating code from a Mako template, I'd like to have a nice syntax to remove leading whitespace (similar to removing newlines with \ at the end of a line). The following code from mako.template import Template # 1)…
AndiDog
  • 68,631
  • 21
  • 159
  • 205
3
votes
1 answer

How to change the mako substitution delimiter characters?

Is it possible to change the "delimiter tags" for expression substitution in the Python Mako templating library? If so, how? e.g.: Instead of
${foobar}
, I would like to use the syntax
{{foobar}}
. I can't seem to find any…
Chris W.
  • 37,583
  • 36
  • 99
  • 136
3
votes
2 answers

How to convert multiple newlines in mako template to one newline?

I am using mako template with python and trying to generate a text file by using a list from python script. A part of code is shown below which is causing problem. % for COMPNAME in tpdob.scalar_modi: ${COMPNAME[0]} ${COMPNAME[1]} ${COMPNAME[2]}…
Aakash Goyal
  • 1,051
  • 4
  • 12
  • 44
3
votes
2 answers

How to properly escape output (for XHTML) in mako?

Despite offering a nice way to escape output using filters, none of them do the right thing. Taking the string: x=u"&\u0092" The filters do the following: x Turns the & into an entity but not the \u0092 (valid XML but not XHTML) h …
Draemon
  • 33,955
  • 16
  • 77
  • 104
3
votes
1 answer

ImportError: no module named mako.template

This line of code in my foobar.py file: from mako.template import * results in an ImportError: No module named mako.template How can I fix this? Both help('modules') and repr(mako) in my Python console assures me that the mako module is installed…
o01
  • 5,191
  • 10
  • 44
  • 85
3
votes
1 answer

handling URLs with dynamic parameters in cherrypy/mako

I do have a quite simple web application written in Python using cherrypy and Mako templates. The most tedious thing is printing links with parameters, especially when I need to incrementally add more parameters, update an existing parameter or…
3
votes
1 answer

Python Mako templating - How can I dynamically decide which def or function to call based on a value in the context?

I would do something like the following in a Mako file: %for operation in operation_list: ${operation['name']} ${${operation['name']}Body()} %endfor <%def name="operationOneBody()"> some stuff <%def name="operationTwoBody()"> …
tadasajon
  • 14,276
  • 29
  • 92
  • 144
3
votes
3 answers

Pyramid "select" form input raise a KeyError

I am trying to access a request.param in my Pyramid application. I saw a topic about checkboxes, but nobody talked about the "select" HTML tag. On the pyramid view side, here is the part of my code which gathers the parameters: if 'form.submitted'…
Julien Tanay
  • 1,214
  • 2
  • 14
  • 20
3
votes
1 answer

OK, I've read all to the unicode/mako posts but I still can get this simple code to work

I've running Python 2.6.6. cat tbuild.py #!/usr/bin/env python # -*- coding: utf-8 -*- # from mako.template import Template _template=""" % for v in my_list: ${'abc'.encode('utf-8')} ${'風連町?'.encode('utf-8')} % endfor """ print…
eorojas
  • 73
  • 7
3
votes
1 answer

Webhelpers with Python Bottle

I've got a Python Bottle application up and running use Mako templating. I'd like to use the webhelpers module (used in Pylons web applications) but I'm not sure how to go about doing this. I'd like to be able to do this in my mako…
writes_on
  • 1,735
  • 2
  • 22
  • 35
3
votes
3 answers

EpicEditor text showing as   instead of space

Not sure if this is an actual problem per se but I'm using Epic Editor to input and save markdown in my GAE application (webpy with mako as the templating engine). I've got a hidden input element in the form which gets populated by the EpicEditor's…
sw00
  • 980
  • 2
  • 16
  • 29
3
votes
1 answer

Possible change Mako's inline begin/end syntax?

I've been using Jinja2 to create and render templates of Bash scripts (among other things) and I've been missing the power of having full python available as in Mako. The thing that keeps me from using Mako at the moment seems rather trivial which…
Catskul
  • 17,916
  • 15
  • 84
  • 113