Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.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
Django 在Reportlab中,表的数据格式是什么_Django_Python 2.7_Reportlab_Pypdf_Pypdf2 - Fatal编程技术网

Django 在Reportlab中,表的数据格式是什么

Django 在Reportlab中,表的数据格式是什么,django,python-2.7,reportlab,pypdf,pypdf2,Django,Python 2.7,Reportlab,Pypdf,Pypdf2,在报告中,我尝试添加行和列,但遇到错误 /billing/invoce_report/'int'对象处的TypeError不可编辑 我认为问题在于,reportlab.platypus.Table对象的数据参数需要是一个列表列表,而不是一个简单的列表。该嵌套列表是一个二维数据网格,即与表相同的结构。第7.1章“表格方法”对此进行了说明 # So this will work: data = [ [1,2,3], [4,5,6], [7,8,9], ] # as will

在报告中,我尝试添加行和列,但遇到错误

/billing/invoce_report/'int'对象处的TypeError不可编辑


我认为问题在于,
reportlab.platypus.Table
对象的数据参数需要是一个列表列表,而不是一个简单的列表。该嵌套列表是一个二维数据网格,即与表相同的结构。第7.1章“表格方法”对此进行了说明

# So this will work:
data = [
    [1,2,3],
    [4,5,6],
    [7,8,9],
]

# as will a single row:
data = [ [1,2,3] ]

# but a simple list with numbers in it will not work (your current data):
data = [1,2,3]

# however, a list of strings appears to work - like table headings?
data = ['testing', '1', '2']

是的,这是真的。这个问题的解决方案是什么?请在产品数据周围多加一对括号:
product\u data=[[…]]
。或者,我看到你说你想要消息中的行和列,所以如果你想要多行,那么就把数据像网格一样排序。但仍然面临错误。就像我在问题中提到的,看看产品数据和pdf数据。请在这里写一些代码,以便我能轻松理解
# So this will work:
data = [
    [1,2,3],
    [4,5,6],
    [7,8,9],
]

# as will a single row:
data = [ [1,2,3] ]

# but a simple list with numbers in it will not work (your current data):
data = [1,2,3]

# however, a list of strings appears to work - like table headings?
data = ['testing', '1', '2']