jinja2 load template from string: TypeError: no loader for this environment specified
<p>I'm using Jinja2 in Flask. I want to render a template from a string. I tried the following 2 methods:</p>

<pre><code> rtemplate = jinja2.Environment().from_string(myString)
 data = rtemplate.render(**data)
</code></pre>

<p>and</p>

<pre><code> rtemplate = jinja2.Template(myString)
 data = rtemplate.render(**data)
</code></pre>

<p>However both methods return:</p>

<pre><code>TypeError: no loader for this environment specified
</code></pre>

<p>I checked the manual and this url: <a href="https://gist.github.com/wrunk/1317933" rel="nofollow">https://gist.github.com/wrunk/1317933</a></p>

<p>However nowhere is specified to select a loader when using a string.</p>

<p>You can provide <code>loader</code> in <code>Environment</code> from <a href="http://jinja.pocoo.org/docs/dev/api/#loaders" rel="nofollow">that list</a></p>

<pre><code>from jinja2 import Environment, BaseLoader

rtemplate = Environment(loader=BaseLoader).from_string(myString)
data = rtemplate.render(**data)
</code></pre>

<p><strong>Edit</strong>: The problem was with <code>myString</code>, it has <code>{% include 'test.html' %}</code> and Jinja2 has no idea where to get template from.</p>

<p><strong>UPDATE</strong></p>

<p>As @iver56 kindly noted, it's better to:</p>

<pre><code>rtemplate = Environment(loader=BaseLoader()).from_string(myString)
</code></pre>

python flask jinja2