当前位置: 首页 > 后端技术 > Python

Django直接使用数据库连接和游标读写数据库

时间:2023-03-26 16:44:45 Python

singledatabasefromdjango.dbimportconnectionwithconnection.cursor()ascursor:cursor.execute('SELECTversion()')row=cursor.fetchone()multipledatabasesfromdjango.dbimportconnectionswithconnections['my_db_alias'].cursor()ascursor:cursor.execute('SELECTversion()')参考连接:直接执行自定义SQL以对多个数据库使用原始游标