title: Dynamic HTML escaping in template in Flask
body: <p>I'm using Flask's jinja2 templates to display a webpage. Now whenever a user inputs some data (in Markdown format) in the text field I send a request to the server and the respective view returns that data converted to HTML. Then using jquery I insert that html in a div.</p>
  
  <p>Now, Flask templates won't render the HTML the way it's meant to be. I've tried using Flask's markup and escape on the server side but it still isn't displaying it properly. I have to figure out a way for templates to completely disregard an area of the template and not autoescape it. I've even tried turning off autoescape by using the <code>{% autoescape off %}</code> tags but I think that only works for stuff inside <code>{{..}}</code> or it only works when the <code>render template</code> function is used</p>
  
  <p>Code for reference:</p>
  
  <p><strong>view function</strong></p>
  
  <pre><code>@app.route("/convert_markdown/", methods=["GET", "POST"])
  def convert_markdown():
  
      content = request.args.get('val')
      value = markdown.convert(content)
  
      return value
  </code></pre>
  
  <p><strong>javascript</strong></p>
  
  <pre><code>$("#content").bind('keyup', function() {
      var value = $( "input:text[name=content]" ).val();
      $( "#preview" ).text( value );
      $.get("/convert_markdown/",{val:value}, function(data) {
          $( "#preview" ).text( data );
      });
  });
  </code></pre>
  
  <p><strong>template- html</strong></p>
  
  <pre><code>&lt;div id="preview"&gt;&lt;/div&gt; 
  </code></pre>