Django应对sql注入攻击的方法:使用djanGo自带的数据库api,它会根据数据库的转换规则,自动转义特殊的SQL参数。在cursor.execute()的sql语句中使用“%s”,而不要在sql内直接添加参数,例如:from dja
使用djanGo自带的数据库api,它会根据数据库的转换规则,自动转义特殊的SQL参数。
在cursor.execute()的sql语句中使用“%s”,而不要在sql内直接添加参数,例如:
from django.db import connection
def user_contacts(request):
user = request.GET['username']
sql = "SELECT * FROM user_contacts WHERE username = %s"
cursor = connection.cursor()
cursor.execute(sql, [user])
# ... do something with the results
--结束END--
本文标题: django如何应对sql注入攻击
本文链接: https://www.lsjlt.com/news/113660.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-05
2024-05-05
2024-05-05
2024-05-05
2024-05-05
2024-05-05
2024-05-05
2024-05-05
2024-05-05
2024-05-05
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0