sanitze fallback

This commit is contained in:
root 2018-08-27 10:51:18 +00:00
parent f26ddd3a41
commit 9c02e2913e

View File

@ -21,7 +21,11 @@ import lxml.html
# Create your models here. # Create your models here.
def sanitize_html(string): def sanitize_html(string):
return '\n'.join(lxml.html.tostring(x) for x in lxml.html.fragment_fromstring(string).iterchildren()) try:
html = '\n'.join(lxml.html.tostring(x) for x in lxml.html.fragment_fromstring(string).iterchildren())
except:
html = ox.strip_tags(string.replace('<br>', '\n')).replace('\n\n', '\n').replace('\n', '<br>')
return html
class Acrolike(models.Model): class Acrolike(models.Model):
title = models.CharField(max_length=255) title = models.CharField(max_length=255)