Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用ExcelResponse将RawQuerySet导出到excel。“错误”;ExcelResponse需要一系列的序列;_Python_Django_Postgresql_Django Views_Export To Excel - Fatal编程技术网

Python 使用ExcelResponse将RawQuerySet导出到excel。“错误”;ExcelResponse需要一系列的序列;

Python 使用ExcelResponse将RawQuerySet导出到excel。“错误”;ExcelResponse需要一系列的序列;,python,django,postgresql,django-views,export-to-excel,Python,Django,Postgresql,Django Views,Export To Excel,我试着将一个视图postgres下载到excel,是否可以用excel响应 from excel_response import ExcelResponse def vw_export_to_Excel(request): data = _Custumer.objects.raw('''select * from vw_customer''') return ExcelResponse(data, 'customer') 迭代模型实例的返回值,而不是序列 使用django.db

我试着将一个视图postgres下载到excel,是否可以用excel响应

from excel_response import ExcelResponse
def vw_export_to_Excel(request):
    data = _Custumer.objects.raw('''select * from vw_customer''')
    return ExcelResponse(data, 'customer')

迭代模型实例的返回值,而不是序列

使用
django.db.connection.cursor()

from django.db import connection
from excel_response import ExcelResponse

def vw_export_to_Excel(request):
    cursor = connection.cursor()
    cursor.execute("select * from vw_customer")
    return ExcelResponse(cursor.fetchall())
或使用:

from excel_response import ExcelResponse

def vw_export_to_Excel(request):
    data = list(_Custumer.objects.values_list())
    return ExcelResponse(data, 'customer')