执行Django原生的sql语句

Django中能用ORM的就用它ORM吧,不建议执行原生SQL,可能会有一些安全问题,

如果实在是SQL太复杂ORM实现不了,那就看看下边执行原生SQL的方法,跟直接使用pymysql基本一致了

from  django.db  import connection

with connection.cursor() as cursor

  cursor.excute('select * from accounts_User')

  row = cursor.fetchall()

return row

原文地址:https://www.cnblogs.com/zhuyafeng/p/9535792.html