Socialify

Folder ..

Viewing remove_tags.py
12 lines (10 loc) • 373.0 B

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import re

from django import template

register = template.Library()

@register.filter(name='remove_tags')
# Takes a string and removes all HTML tags from it
def remove_tags(value):
    # replace anything that matches '<tag>' or '</tag>' with ''
    pattern = r'(<([^>]+)>)'
    # replace globally and ignore case
    return re.sub(pattern, '', value, flags=re.IGNORECASE)