@commit_on_success def my_custom_sql_view(request, value): from django.db import connection, transaction cursor = connection.cursor() # Data modifying operation cursor.execute("UPDATE bar SET foo = 1 WHERE baz = %s", [value]) # Since we modified data, mark the transaction as dirty transaction.set_dirty() # Data retrieval operation. This doesn't dirty the transaction, # so no call to set_dirty() is required. cursor.execute("SELECT foo FROM bar WHERE baz = %s", [value]) row = cursor.fetchone() return render_to_response('template.html', {'row': row}) 查看Django ORM执行的SQL语句 : connection.queries
下面关于Python的文章您也可能喜欢,不妨看看:
CentOS上源码安装Python3.4
《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版]
《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码]
在Ubuntu下用Python搭建桌面算法交易研究环境