python - 下载文件及pymysql
下载文件
from django.http import HttpResponse, Http404, StreamingHttpResponse, FileResponse def f(request): file = open('/Users/ct/dev_ops_3/upload/front_source/5/download/bussiness.zip', 'rb') response = FileResponse(file) response['Content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment;filename="bussiness.zip"' return response
pymysql
pymysql pip install pymysql .... ... sql语句时间的判断 https://www.cnblogs.com/baiyangcao/p/pymssql_basic.html with使用方法: conn = pymssql.connect(server, user, password, database) cursor = conn.cursor(as_dict=True) cursor.execute('SELECT * FROM persons WHERE salesrep=%s', 'John Doe') for row in cursor: print("ID=%d, Name=%s" % (row['id'], row['name'])) conn.close() 使用with语句(上下文管理器) 可以通过使用with语句来省去显示的调用close方法关闭连接和游标 with pymssql.connect(server, user, password, database) as conn: with conn.cursor(as_dict=True) as cursor: cursor.execute('SELECT * FROM persons WHERE salesrep=%s', 'John Doe') for row in cursor: print("ID=%d, Name=%s" % (row['id'], row['name']))