Python implementation of Magery templates
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
magery
tests
.gitignore
.gitmodules
LICENSE.txt
README.md
setup.cfg
setup.py

README.md

Python Magery

A server-side implementation of the Magery templating library for Python 2 and 3. See the Magery README for template syntax.

In the example directory is a Flask app demonstrating server and client code sharing templates.

Installation

pip install magery

API

import magery

compile_templates(filename, templates=None)

Parses templates from filename, returns a dictionary of templates. If templates is not None it will extend the existing templates dictionary instead of returning a new one.

templates = magery.compile_templates('./template.html')

Template.render_to_string(data)

Render a compiled template using data, and return the output as a string.

templates = magery.compile_templates('./template.html')

data = {'name': 'world'}
templates['app'].render_to_string(data);

Template.write(data, out)

Render a compile template using data, and write the result to the IO stream out.

templates = magery.compile_templates('./template.html')

with open('output.html', 'w', encoding='utf-8') as f:
    data = {'name': 'world'}
    templates['app'].write(data, f);