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,530 points
568 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,780 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,080 points
306 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 1, 2020 in Python by Niroj
• 82,780 points
1,225 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,780 points
1,868 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,780 points
868 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,780 points
377 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,780 points
3,650 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,780 points
3,280 views