i'm using jinja2 in flask. want render template string. tried following 2 methods:
rtemplate = jinja2.environment().from_string(mystring) data = rtemplate.render(**data)
and
rtemplate = jinja2.template(mystring) data = rtemplate.render(**data)
however both methods return:
typeerror: no loader environment specified
i checked manual , url: https://gist.github.com/wrunk/1317933
however specified select loader when using string.
you can provide loader
in environment
that list
from jinja2 import environment, baseloader rtemplate = environment(loader=baseloader).from_string(mystring) data = rtemplate.render(**data)
edit: problem mystring
, has {% include 'test.html' %}
, jinja2 has no idea template from.
update
as @iver56 kindly noted, it's better to:
rtemplate = environment(loader=baseloader()).from_string(mystring)
Comments
Post a Comment