Skip to content

Instantly share code, notes, and snippets.

@sxslex
Last active August 2, 2019 02:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sxslex/822bd2405885294747b86aac187f1aa8 to your computer and use it in GitHub Desktop.
Save sxslex/822bd2405885294747b86aac187f1aa8 to your computer and use it in GitHub Desktop.
exemplo jinja2 tojson
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