Skip to content

caolan/python-magery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);

About

Python implementation of Magery templates

Resources

License

Stars

Watchers

Forks

Packages

No packages published