title: Using utf-8 characters in a Jinja2 template
body: <p>I'm trying to use utf-8 characters when rendering a template with Jinja2. Here is how my template looks like:</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html manifest="" lang="en-US"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;{{title}}&lt;/title&gt;
  ...
  </code></pre>
  
  <p>The title variable is set something like this:</p>
  
  <pre><code>index_variables = {'title':''}
  index_variables['title'] = myvar.encode("utf8")
  
  template = env.get_template('index.html')
  index_file = open(preview_root + "/" + "index.html", "w")
  
  index_file.write(
      template.render(index_variables)
  )
  index_file.close()
  </code></pre>
  
  <p>Now, the problem is that <strong>myvar</strong> is a message read from a message queue and can contain those special utf8 characters (ex. "Séptimo Cine"). </p>
  
  <p>The rendered template looks something like:</p>
  
  <pre><code>...
      &lt;title&gt;S\u00e9ptimo Cine&lt;/title&gt;
  ...
  </code></pre>
  
  <p>and I want it to be:</p>
  
  <pre><code>...
      &lt;title&gt;Séptimo Cine&lt;/title&gt;
  ...
  </code></pre>
  
  <p>I have made several tests but I can't get this to work.</p>
  
  <ul>
  <li><p>I have tried to set the title variable without <strong>.encode("utf8")</strong>, but it throws an exception (<em>ValueError: Expected a bytes object, not a unicode object</em>), so my guess is that the initial message is unicode</p></li>
  <li><p>I have used <strong>chardet.detect</strong> to get the encoding of the message (it's "ascii"), then did the following: myvar.decode("ascii").encode("cp852"), but the title is still not rendered correctly.</p></li>
  <li><p>I also made sure that my template is a UTF-8 file, but it didn't make a difference.</p></li>
  </ul>
  
  <p>Any ideas on how to do this?</p>