Bill Ray
Bill Ray

Reputation: 15

Why is the column and width of a table in python creating an error

I'm creating a simple four column, one row table. However, when the code executes I receive the following error

Table 4 rows X 1 cols> with cell (0,0) containing 'D' data error - 1 columns in data but 4 in column widths".

The code is as follows:

colwidths = (46, 76, 48, 40)  
rowheights = (20)  
tabledata = ('DATE ', '3-20-2016', 'FIELD # ', '1')  
t = Table((tabledata), (colwidths), (rowheights))  

Upvotes: 1

Views: 2959

Answers (2)

I encountered a similar problem this week so i will put my solution here for others.

It seems there are two main causes:

  1. Your queryset may not be producing any iterable values - kindly check.

OR

  1. If you have several tables in a page, then one of your tables is not formatted well e.g. you have a <tr> ...<tr> instead of <tr> ...</tr>. note the closing /

My approach to this problem is to split the whole page into partials (with each table as a partial) and load them in the browser one by one.

You are likely to identify the table causing the error.

Upvotes: 1

Paul Rooney
Paul Rooney

Reputation: 21609

You simply need to wrap tabledata in another iterable to ensure its interpreted as all 5 items being on a single row, instead of 5 rows containing a single item? i.e.

tabledata = [('DATE ', '3-20-2016', 'FIELD # ', '1')]

Upvotes: 1

Related Questions