0
以下是我有:如何關閉django 1.8數據庫遊標和連接?
from django.db import connection
class Command(BaseCommand):
option_list = BaseCommand.option_list
def handle(self, *labels, **options):
with connection.cursor() as cursor:
# Drop database
cursor.execute("drop database if exists test_db;")
# Create database again
cursor.execute("create database test_db;")
凡在這一塊我可以關閉數據庫光標和連接,我該怎麼調用來關閉它們?
這僅關閉光標...我希望能夠關閉數據庫連接太...我如何明確地做到這一點? – Becks
當退出'with'模塊時,'cursor'會自動關閉(即使出現異常) –