190👍
✅
Django provides an utility function to remove HTML tags:
from django.utils.html import strip_tags
my_string = '<div>Hello, world</div>'
my_string = strip_tags(my_string)
print(my_string)
# Result will be "Hello, world" without the <div> elements
This function used to be unsafe on older Django version (before 1.7) but nowadays it is completely safe to use it. Here is an article that reviewed this issue when it was relevant.
- [Django]-Can't connect to local MySQL server through socket '/tmp/mysql.sock
- [Django]-Why is assertDictEqual needed if dicts can be compared by `==`?
- [Django]-What is the easiest way to clear a database from the CLI with manage.py in Django?
- [Django]-Django migration error :you cannot alter to or from M2M fields, or add or remove through= on M2M fields
- [Django]-Django: add image in an ImageField from image url
- [Django]-How to set-up a Django project with django-storages and Amazon S3, but with different folders for static files and media files?
Source:stackexchange.com