Mako Templates for Python

Related tags

Template Engine mako
Overview

Mako Templates for Python

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.

Nutshell

<%inherit file="base.html"/>
<%
    rows = [[v for v in range(0,10)] for row in range(0,10)]
%>

 
  
    % for row in rows:
        ${makerow(row)}
    % endfor

 
<%def name="makerow(row)"> % for name in row: ${name}\ % endfor

Philosophy

Python is a great scripting language. Don't reinvent the wheel...your templates can handle it !

Documentation

See documentation for Mako at https://docs.makotemplates.org/en/latest/

License

Mako is licensed under an MIT-style license (see LICENSE). Other incorporated projects may be licensed under different licenses. All licenses allow for non-commercial and commercial use.

Comments
  • Update for sphinx internal structure change layout

    Update for sphinx internal structure change layout

    As reported upstream in sphinx: https://github.com/sphinx-doc/sphinx/pull/2396

    It was a structural change in sphinx-1.4. I'm not sure if this is the proper fix, but it does let the doc build pass, in my testing.

    Originally reported at http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=830178.

    Signed-off-by: Nishanth Aravamudan [email protected]

    opened by nacc 8
  • Add more source comments to the code generator

    Add more source comments to the code generator

    I'm experimenting with adding Mako support to coverage.py. In order to fully parse the generated Python files to correlate generated lines with source lines, I've added more comment output to identify the lines that aren't associated with any source line.

    This is probably not all the places that need to be commented, but seems to work well for the templates I'm using. If you have a better way to do this, or a different way to accomplish the same thing, I'm completely open to other ideas.

    opened by nedbat 6
  • Support py3k kwonly args

    Support py3k kwonly args

    They were being correctly parsed already, but a template like this:

    <%def name="asdf(*qwert, zxcv='hi')">${zxcv}</%def>
    

    would generate code like this:

    def render_asdf(context,*qwert):
        __M_caller = context.caller_stack._push_frame()
        try:
            zxcv = context.get('zxcv', UNDEFINED)
        ...
    

    which would then either TypeError when called with the required keyword argument, or (if there were also a **kwargs) have the argument overwritten by UNDEFINED right out of the gate.

    Should work now. Added a few tests. Everything passes on Python 2.7, Python 3.3, and PyPy 2.2.1 (except for two tests that fail PyPy in Beaker somewhere, so not a Mako problem).

    Inspired by... mitsuhiko, or python-future, or someone?, I added a compat.py2k, so code can be written as though Python 3 were the default and Python 2 were the special case.

    I also made a best effort at the _ast-less code path; four tests fail, but all four of them are problems with how Pygments decided to color the syntax, so I assume that's just an inherent issue with the compiler module. (Two of them are marked as requiring Python 2.5+, so will never run in practice anyway.)

    opened by eevee 6
  • Improve lexer with better string handling and grouping parens/brackets

    Improve lexer with better string handling and grouping parens/brackets

    This allows the lexer to correctly handle strings like:

    ${'backslash quote right-curly is \\\'}'}
    

    And also allows users to use the bitwise-or operator to mean bitwise or simply by enclosing the expression inside parens:

    ${(0x5432 | 0x8000)}
    

    or by using it in the middle of a dictionary literal:

    ${ {'foo-val': 0x43 | 0x100, 'bar-val': 0x22 | 0x100}[thing+'-val']}
    

    or inside brackets:

    ${ big_lookup_dict[index_low | (indexhigh << 3)] }
    

    Basically, only "top level" uses of the vertical bar mean pipe.

    (Note that currently, any non-top-level use of the vertical bar in an expression just results in a syntax error in the generated python, so no working code is affected by this change)

    opened by fizbin 4
  • modernize setup.py:

    modernize setup.py:

    • use environment markers - re-enabled universal wheels
    • use setuptools_scm for version management (requires semantic version tags [1.0.2]
    • stop supporting python 3 < 3.3
    • normalize htmlhelp doc name
    • remove dead entries from MANIFEST.in
    opened by mindw 4
  • Remove redundant Python<2.6 code

    Remove redundant Python<2.6 code

    Includes PR https://github.com/zzzeek/mako/pull/26 so Travis CI passes. The last two commits are unique to this PR.


    Since Mako 1.0.0, Python 2.6 has been the minimum supported version:

    [general] Compatibility changes; in order to modernize the codebase, Mako is now dropping support for Python 2.4 and Python 2.5 altogether. The source base is now targeted at Python 2.6 and forwards.

    http://docs.makotemplates.org/en/latest/changelog.html#change-b602a175c0ec26eaa4f42962d23cca96

    This removes redundant code only relevant to Python 2.5 or earlier.

    It also adds python_requires to setup.py, so pip won't install this version on Python 2.5 or earlier. For people with older versions, pip will install the next Mako version down.

    Are all Python 3.x versions supported? If not, I'll add those to python_requires as well.

    opened by hugovk 3
  • travis!

    travis!

    https://travis-ci.org/mindw/mako/builds/77541154

    The following image (svg or png) should be embedded into the readme: https://img.shields.io/travis/zzzeek/mako.svg

    opened by mindw 3
  • Double brace expression

    Double brace expression

    I am using mako in shell scripts where the ${}-syntax is already in use by shell variables. So I have to use <%text>-blocks everywhere which is not convinient. This patch provides a way to specifiy an alternate expression syntax, namely double-braces: {{ ... }}.

    opened by megahallon 3
  • added arg_stringname function to _ast_util.py

    added arg_stringname function to _ast_util.py

    This is to be compatible with python3.4 where kwarg and vararg objects are _ast.arg as opposed to Name objects in earlier versions. The _ast.arg object cannot be implicitly converted to a string. This lead to 4 errors in the test suite.

    As of this commit all tests pass under python3.4a2

    opened by Zer0- 3
  • Allow literal string argument that starts with a

    Allow literal string argument that starts with a "#".

    Without this change, when running setup.py extract_messages, we would get error:

    TokenError: ('EOF in multi-line statement', (2, 0))
    

    Looking at the unit test, it seems like a literal string argument in the form of "_('xxx')" is supposed to be picked up by Babel. However, that contradicts with the documentation, which states:

    When using tags, the values of the arguments are taken as literal strings by default. To embed Python expressions as arguments, use the embedded expression format

    So, as a side effect of this commit, the convenience of "_('xxx')" has been removed. Probably can add it back if necessary for backward compatibility.

    opened by sayap 3
  • Marked some docstrings as raw strings to address the invalid escape warning on Python 3.6+

    Marked some docstrings as raw strings to address the invalid escape warning on Python 3.6+

    Starting with 3.6.0, escape sequences in string and byte literals emit a deprecation warning for invalid backslash escapes. This change marks a handful of docstrings as raw strings to address this problem.

    opened by ygingras 2
Owner
mike bayer
SQLAlchemy, Alembic, Mako, dogpile.cache
mike bayer
✈️ HTML Template engine for python. Supports XSS preventation and many more!

Htmotor HTML Template Engine for Python! Installation: Open your terminal and type pip install htmotor.

Penguen 3 Nov 6, 2022
A simple, elegant Python based web templating engine (part of web.py).

Templator Simple, elegant Python based web templating (part of web.py). If you are familiar with Python, there is no new syntax to learn. This is a st

Dan 1 Dec 13, 2021
Blender Game Engine Game Type Templates Logic Bricks (and Python script) based Game Templates for Blender

Blender-Game-Engine-Templates Blender Game Engine Game Type Templates Logic Bric

null 3 Oct 25, 2022
A command-line utility that creates projects from cookiecutters (project templates), e.g. Python package projects, VueJS projects.

Cookiecutter A command-line utility that creates projects from cookiecutters (project templates), e.g. creating a Python package project from a Python

null 18.6k Dec 30, 2022
Tweak the form field rendering in templates, not in python-level form definitions. CSS classes and HTML attributes can be altered.

django-widget-tweaks Tweak the form field rendering in templates, not in python-level form definitions. Altering CSS classes and HTML attributes is su

Jazzband 1.8k Jan 2, 2023
A command-line utility that creates projects from cookiecutters (project templates), e.g. Python package projects, VueJS projects.

Cookiecutter A command-line utility that creates projects from cookiecutters (project templates), e.g. creating a Python package project from a Python

null 18.6k Jan 2, 2023
Static site generator for designers. Uses Python and Django templates.

News Cactus 3 is out! We're happy to announce Cactus 3. It brings a set of great new features like asset fingerprinting, an asset pipeline, pretty url

null 3.4k Jan 1, 2023
Tweak the form field rendering in templates, not in python-level form definitions. CSS classes and HTML attributes can be altered.

django-widget-tweaks Tweak the form field rendering in templates, not in python-level form definitions. Altering CSS classes and HTML attributes is su

Jazzband 1.8k Jan 6, 2023
Simple reuse of partial HTML page templates in the Jinja template language for Python web frameworks.

Jinja Partials Simple reuse of partial HTML page templates in the Jinja template language for Python web frameworks. (There is also a Pyramid/Chameleo

Michael Kennedy 106 Dec 28, 2022
A command-line utility that creates projects from cookiecutters (project templates), e.g. Python package projects, VueJS projects.

Cookiecutter A command-line utility that creates projects from cookiecutters (project templates), e.g. creating a Python package project from a Python

null 18.7k Jan 8, 2023
PyPC is a very simple tool that creates Python projects from templates.

PyPC (Python Project Creator) PyPC is a very simple tool that creates Python projects from templates. In 0.1v#alpha, custom template creation will be

art3m1s 1 Nov 26, 2021
Library and command-line utility for rendering projects templates.

A library for rendering project templates. Works with local paths and git URLs. Your project can include any file and Copier can dynamically replace v

null 808 Jan 4, 2023
Formatting of dates and times in Flask templates using moment.js.

Flask-Moment This extension enhances Jinja2 templates with formatting of dates and times using moment.js. Quick Start Step 1: Initialize the extension

Miguel Grinberg 358 Nov 28, 2022
A flask template with Bootstrap 4, asset bundling+minification with webpack, starter templates, and registration/authentication. For use with cookiecutter.

cookiecutter-flask A Flask template for cookiecutter. (Supports Python ≥ 3.6) See this repo for an example project generated from the most recent vers

null 4.3k Dec 29, 2022
Full control of form rendering in the templates.

django-floppyforms Full control of form rendering in the templates. Authors: Gregor Müllegger and many many contributors Original creator: Bruno Renié

Jazzband 811 Dec 1, 2022
Formatting of dates and times in Flask templates using moment.js.

Flask-Moment This extension enhances Jinja2 templates with formatting of dates and times using moment.js. Quick Start Step 1: Initialize the extension

Miguel Grinberg 318 Feb 17, 2021
Implementation of "Deep Implicit Templates for 3D Shape Representation"

Deep Implicit Templates for 3D Shape Representation Zerong Zheng, Tao Yu, Qionghai Dai, Yebin Liu. arXiv 2020. This repository is an implementation fo

Zerong Zheng 144 Dec 7, 2022
NetBox plugin that stores configuration diffs and checks templates compliance

Config Officer - NetBox plugin NetBox plugin that deals with Cisco device configuration (collects running config from Cisco devices, indicates config

null 77 Dec 21, 2022
Use heroicons in your Django and Jinja templates.

heroicons Use heroicons in your Django and Jinja templates. Requirements Python 3.6 to 3.9 supported. Django 2.2 to 3.2 supported. Are your tests slow

Adam Johnson 52 Dec 14, 2022
Formatting of dates and times in Flask templates using moment.js.

Flask-Moment This extension enhances Jinja2 templates with formatting of dates and times using moment.js. Quick Start Step 1: Initialize the extension

Miguel Grinberg 358 Nov 28, 2022