how to filter out the html tags contained in strings in django templates.
there are two ways:
{{ myvar|striptags }}
If the string of myvar is A common way <br> to handle transactions <br> on the web is to wrap <br> each request in a transaction.<br>
, then the output result would be: A common way to handle transactions on the web is to wrap each request in a transaction
.
If you want to use it in the view function of python django, here is an example:
class AddressForm(forms.ModelForm):
class Meta:
model = Address
def clean(self):
from django.utils.html import strip_tags
cleaned_data = super(AddressForm, self).clean()
cleaned_data['first_name'] = strip_tags(cleaned_data.get('first_name'))
return cleaned_data