How to strip html javascript from text input in django

0 votes
What is the easiest way to strip all html/javascript from a string?
Aug 17, 2020 in Python by kartik
• 37,520 points
1,895 views

1 answer to this question.

0 votes

Hello @kartik,

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

Hope it helps!!

Thank You!

answered Aug 17, 2020 by Niroj
• 82,840 points

Related Questions In Python

0 votes
0 answers
0 votes
0 answers

How to read lines from compressed text files in Python

Is it easy to read a line ...READ MORE

Dec 27, 2018 in Python by Anirudh
• 2,090 points
979 views
0 votes
1 answer

How to order_by a JSON from serializers.py file in django rest framework?

Hello @kartik, There's an easy way, just override ...READ MORE

answered Jul 2, 2020 in Python by Niroj
• 82,840 points
5,892 views
0 votes
1 answer

How can I render HTML to PDF in Django site?

Hello @kartik, Use this code to generate the PDF ...READ MORE

answered Jul 29, 2020 in Python by Niroj
• 82,840 points
4,540 views
0 votes
1 answer

How to temporarily disable a foreign key constraint in MySQL?

Hello @kartik, To turn off foreign key constraint ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,840 points
2,501 views
0 votes
1 answer

How do I use Django templates without the rest of Django?

Hello @kartik, Let's say you have this important ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,840 points
1,578 views
0 votes
1 answer

How to output text from database with line breaks in a django template?

Hello @kartik, Use linebreaks or linebreaksbr filter: {{ text|linebreaks }} Or surround the text ...READ MORE

answered Jun 24, 2020 in Python by Niroj
• 82,840 points
13,542 views
0 votes
1 answer

How to get value from form field in django framework?

Hello @kartik, Using a form in a view can ...READ MORE

answered Jun 30, 2020 in Python by Niroj
• 82,840 points
9,162 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP