Last active
January 15, 2016 06:32
-
-
Save dmitryhd/18c3c0b1beddfe039569 to your computer and use it in GitHub Desktop.
Jinja2 template example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python2 | |
| # -*- coding: utf-8 -*- | |
| """ """ | |
| from jinja2 import Template | |
| # python3 | |
| def render_jinja(template: str, parameters: dict) -> str: | |
| """ | |
| Usage: | |
| >>> render_jinja('example template: {{msg}}', {'msg': 'message'}) | |
| 'example template: message' | |
| """ | |
| return Template(template).render(parameters) | |
| # python2 | |
| def render_jinja(template, parameters): | |
| """ | |
| Usage: | |
| >>> render_jinja('example template: {{msg}}', {'msg': 'message'}) | |
| 'example template: message' | |
| """ | |
| return Template(template).render(parameters) | |
| if __name__ == "__main__": | |
| import doctest | |
| doctest.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment