django没有dictcursor的解决办法

    def dictfetchall(self, cursor):
        """将游标返回的结果保存到一个字典对象中,解决django中没有dictcursor的情况"""
        return [dict(zip([col[0] for col in cursor.description], row)) for row in cursor.fetchall()]
    from django.db import connection, transaction
 	cursor = connection.cursor()
 	cursor.execute(_sql, _args)  #要执行的sql语句。
    out_ticket_info = self.dictfetchall(cursor)

猜你喜欢

转载自blog.csdn.net/funnyPython/article/details/83824526