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

Form Initialization with ToscaWidgets

Question: How do I prefill a CheckBoxTable from ToscaWidgets with values. Background: I've looked everywhere and I can't seem to figure out how to initialize a particular form field with ToscaWidgets. Most form fields seem to respond just fine to…
Robbie
  • 892
  • 2
  • 7
  • 19
3
votes
1 answer

How can I use Py3k-style string formatting within Mako templates?

I'm working on a Pyramid project using Mako templates, and I'm trying to display some floating-point numbers. The numbers are expressed as floats in my code, but I'd like to truncate them to 2 decimal places for display to users. It's…
Brighid McDonnell
  • 4,293
  • 4
  • 36
  • 61
2
votes
1 answer

Mako for python

I am a newbie for mako and want to create .py scripts programatically from a template .py script. So does something like this work Lets say my template script has a variable var1 = ${var1}, that takes say integer values. I want to be able to create…
ganesh reddy
  • 1,842
  • 7
  • 23
  • 38
2
votes
1 answer

Python+Pyramid+Mako: What is the difference between the context in event, context in view and context in template?

I've been trying hard to understand this, but can't quite put a finger on a precise documentation about it. I am quite confused about the different meaning of context in this Python Pyramid+Mako setup. Here is some code snippets (tell me if you need…
Danosaure
  • 3,578
  • 4
  • 26
  • 41
2
votes
2 answers

Get Dreamweaver to highlight .mako files as .html

Ideally, I would like to be able to treat a site built using Mako templates in Dreamweaver, as I'm merely working on the design aspect. I imagine the work will go much faster if I could edit .mako files in Dreamweaver and have it render the file…
Jon Mitten
  • 1,965
  • 4
  • 25
  • 53
2
votes
2 answers

Mako csrf_token like in Django templates

I my recent Django-project I use mako templates. About Cross Site Request Forgery CSRF. In django templates there is the tag {% csrf_token %} to protect from hackers. What about mako templates? Is there any analog of csrf_token or there is another…
Vitalii Ponomar
  • 10,686
  • 20
  • 60
  • 88
2
votes
2 answers

CherryPy / Mako path issue with %include on Linux (works on Windows)

I have an application with the following files /path_to_app app.py /html page.html /js page.js In app.py I load and render a mako template. The template file is page.html in the html directory. That page contains contains a…
Larry Lustig
  • 49,320
  • 14
  • 110
  • 160
2
votes
1 answer

Using "class" as an option to a Mako Macro

I am writing a Mako extension that assist in rendering forms. I was making excellent progress until I ran into one big stumbling block regarding css classes. I want to write code that looks like this: <%fp:form method="post" action=""…
dave mankoff
  • 17,379
  • 7
  • 50
  • 64
2
votes
1 answer

Template hook is not being triggered in custom Nikola theme

I am trying to write a custom theme for Nikola, a static site generator. I have been mostly following their tutorial but have run into a problem. I want to show certain HTML specifically on pages (not on posts) in the spot where the page_header…
soapergem
  • 9,263
  • 18
  • 96
  • 152
2
votes
1 answer

Inline if statement escapes HTML characters

So I'm playing with Mako on Pyramid and I'm trying to do inline if statements.
  • ${'Opinions
  • ' if whichnav == 'opinions' else 'Opinions'} Outputs:
  • <a href="#">Opinions</a></li> Whereas: % if…
  • Jonathan Ong
    • 19,927
    • 17
    • 79
    • 118
    2
    votes
    2 answers

    Capture body content in Mako?

    Is it possible to get the rendered body content from within a Mako template? What I mean is that I can display the body using ${self.body()}, but what if I want to do something to it first?
    Brendan Long
    • 53,280
    • 21
    • 146
    • 188
    2
    votes
    1 answer

    Python+mako Unicode problem

    I am trying to read a DB table contents and display it as a web page using mako and bottle. The table has some Unicode (utf-8) fields in it. UnicodeDecodeError('ascii', 'MOTOROLA MILESTONE\xe2\x84\xa2 PLUS', 18, 19, 'ordinal not…
    Adam Matan
    • 128,757
    • 147
    • 397
    • 562
    2
    votes
    1 answer

    Mako's analog of Django's "spaceless" tag?

    Is there a mechanism in Mako templates that would allow me to remove extra spaces from the template output, similar to Django's {% spaceless %} tag?
    akonsu
    • 28,824
    • 33
    • 119
    • 194
    2
    votes
    1 answer

    Python module in path: ImportError raised in mako template

    There is an ImportError that has the potential to drive me mad. The situation looks like this: tests/ testWebsite.py website/ __init__.py __main__.py _webtools/ __init__.py templatedefs.py ... _templates/ …
    Boldewyn
    • 81,211
    • 44
    • 156
    • 212
    2
    votes
    2 answers

    Access variables defined in Mako namespace

    Normally, "importing" a namespace in Mako appears to only allow access to defs. ## base.mako <% somevar = ["one", "two", "three"] %> <%def name="foo()">Bar And an importing template: ## child.mako <%namespace name="base" file="base.mako"…
    sink
    • 41
    • 1
    • 3