Sanitising user input using Python

后端 未结 7 899
小鲜肉
小鲜肉 2020-12-04 07:36

What is the best way to sanitize user input for a Python-based web application? Is there a single function to remove HTML characters and any other necessary characters combi

7条回答
  •  悲哀的现实
    2020-12-04 08:00

    If you are using a framework like django, the framework can easily do this for you using standard filters. In fact, I'm pretty sure django automatically does it unless you tell it not to.

    Otherwise, I would recommend using some sort of regex validation before accepting inputs from forms. I don't think there's a silver bullet for your problem, but using the re module, you should be able to construct what you need.

提交回复
热议问题