Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/caolan/python-magery
Python implementation of Magery templates
https://github.com/caolan/python-magery
Last synced: 17 days ago
JSON representation
Python implementation of Magery templates
- Host: GitHub
- URL: https://github.com/caolan/python-magery
- Owner: caolan
- License: mit
- Created: 2016-05-30T19:32:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-10-22T23:18:32.000Z (about 5 years ago)
- Last Synced: 2024-10-11T07:34:50.138Z (about 1 month ago)
- Language: Python
- Size: 59.6 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Python Magery
A server-side implementation of the [Magery][magery] templating library for
Python 2 and 3. See the Magery [README][magery] for template syntax.In the [example](example) directory is a [Flask][flask] app demonstrating
server and client code sharing templates.## Installation
```no-highlight
pip install magery
```## API
```python
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.```python
templates = magery.compile_templates('./template.html')
```### Template.render\_to\_string(data)
Render a compiled template using `data`, and return the output as a
string.```python
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`.```python
templates = magery.compile_templates('./template.html')with open('output.html', 'w', encoding='utf-8') as f:
data = {'name': 'world'}
templates['app'].write(data, f);
```[magery]: https://github.com/caolan/magery/
[flask]: http://flask.pocoo.org/