Last active
August 2, 2019 02:36
-
-
Save sxslex/822bd2405885294747b86aac187f1aa8 to your computer and use it in GitHub Desktop.
exemplo jinja2 tojson
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
def template(html, **params): | |
import jinja2 | |
env = jinja2.Environment(loader=FileSystemLoader('')) | |
def tojson(s): | |
import json | |
return json.dumps(s) | |
env.filters['tojson'] = tojson | |
template = env.from_string(html) | |
return template.render(context=params, **params) | |
print(template('{{ context|tojson }}', name='slex', value=39 )) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment