If I send something like
{
"description": "Hello World <script>alert('hacked');</script>"
}
to my django rest framework view, I want to get rid of the the script tags.
strip_tags
?Django by default sanitizes quoted data.
To sanitize a string input which you want to store to the database (for example a customer name) you need either to escape it or plainly remove any quotes (', ") from it. This effectively prevents classical SQL injection which can happen if you are assembling an SQL query from strings passed by the user.
validated_data is an OrderedDict and you can see it only after is_valid() and is_valid() == True.
Django REST framework is a powerful and flexible toolkit for building Web APIs. Some reasons you might want to use REST framework: The Web browsable API is a huge usability win for your developers. Authentication policies including packages for OAuth1a and OAuth2.
Ignore the answers here, they are terrible.
Use bleach. You won't get every edge case. This is the situation to use a library in. Your client has control of the client side by definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With