title: Allowing basic html markup in django
body: <p>Im creating an app that will process user submitted content. I would like to enable users to make their text-based content look pretty with basic html markup i.e &lt; i > &lt; b > &lt; br > . However I do want to prevent them from using things like script tags. Django will auto escape everything therefore it will also disable all safe markup. I can disable this by using:</p>
  
  <p><code>{{ somevar|safe }}</code> or <code>{% autoescape off %}</code></p>
  
  <p>However this will also enable all harmfull script tags. Django does provide the linebreaks filter tag which transform white space to br or p tags while keeping the html safe: </p>
  
  <pre><code>{{ somevar|linebreaks }}
  </code></pre>
  
  <p>Unfortunately I am not aware of any filters that allow b or i tags to be used.</p>
  
  <p>So I am wondering if there is a smart solution to this problem. And if you suggest a third party library would it be best to employ the solution when saving the model or when rendering the content.</p>
  
  <hr>
  
  <h2>UPDATE</h2>
  
  <p>In the end I went with this solution <a href="https://stackoverflow.com/questions/699468/python-html-sanitizer-scrubber-filter">Python HTML sanitizer / scrubber / filter</a>. This latter answer provide a way to use the Beautiful Soup library to remove all unwanted html tags from user submitted content. This can be done before saving the model therefore making it safe to use the template filter <code>{{ somevar|safe }}</code> when rendering the page. </p>