Skip to content

Instantly share code, notes, and snippets.

@DWboutin
Created August 23, 2018 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DWboutin/a9563f8c99a31fa5acb8c479a4d94232 to your computer and use it in GitHub Desktop.
Save DWboutin/a9563f8c99a31fa5acb8c479a4d94232 to your computer and use it in GitHub Desktop.
Django filter to transform HTML to a string with tags replaced by white spaces
from django import template
from django.utils.html import format_html
from django.template.defaultfilters import stringfilter
register = template.Library()
@register.filter(name='convert_tags_to_space')
@stringfilter
def convert_tags_to_space(value):
import re
return re.sub('<.*?>', ' ', value).strip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment