Python 从django shell导出到Excel

Python 从django shell导出到Excel,python,django,excel,shell,Python,Django,Excel,Shell,我有一个从服务器获取数据的函数,并且我采用了字典格式。现在我想在django shell中运行该函数,并在本地驱动器中生成该文件。 这是我生成excel的程序,它有我不需要的HttpResponse,所以我需要做什么更改 def to_excel(excelStr, filename): """ To Generate Excel Sheets """ response = HttpResponse(excelStr, mimetype='application/vnd.ms-excel

我有一个从服务器获取数据的函数,并且我采用了字典格式。现在我想在django shell中运行该函数,并在本地驱动器中生成该文件。 这是我生成excel的程序,它有我不需要的HttpResponse,所以我需要做什么更改

def to_excel(excelStr, filename):  

""" To Generate Excel Sheets """

response = HttpResponse(excelStr, mimetype='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename=%s.xls' \
    % str(filename)
return response
with open('%s.xls' % (filename,)) as f:
    f.write(excelStr)