title: How to apply django/jinja2 template filters 'escape' and 'linebreaks' correctly?
body: <p>I'm currently trying to escape a variable using django templating filters as below.
  I use a jinja2 template engine instead of just django's primary templateing engine</p>
  
  <pre><code>{{ my_variable|escape|linebreaks }}
  </code></pre>
  
  <p>the output of a string with newlines is as follows:</p>
  
  <pre><code>Lorem ipsum &lt;br /&gt; dolor sit amet &lt;br /&gt;rg srg
  gs rgsr rsg serg&lt;br /&gt;r srg
  </code></pre>
  
  <p>Ideally the</p>
  
  <pre><code>&lt;br /&gt;
  </code></pre>
  
  <p>is not supposed to be escaped, as it is added by the "linebreaks" filter. There are no html tags with the original string.</p>
  
  <p>I've tried:</p>
  
  <pre><code>{{ my_variable|linebreaks|escape }}
  </code></pre>
  
  <p>But, it turns out even worse:</p>
  
  <pre><code>&lt;p&gt;Lorem ipsum &lt;br /&gt; dolor sit amet &lt;br /&gt;rg srg&lt;/p&gt;
  &lt;p&gt;gs rgsr rsg serg&lt;br /&gt;r srg&lt;/p&gt;
  </code></pre>
  
  <p>Does anyone knows whether I did something wrong with applying the template filter, and/or able to point me in the right direction?</p>
  
  <p>Thanks.</p>