0
I’m making a table through 3 lists generated in the views, but I can’t leave the table configured correction in html, would be 3 columns and 60 lines, but they are not adjusted correctly, follow my HTML code:
<table>
<tr>
<td>Horario</td>
<td>Ligado</td>
<td>Desligado</td>
</tr>
{% for x in teste4 %}
<tr>
<td>{{ x }}</td>
</tr>
{% endfor %}
{% for y in tabela1 %}
<tr>
<td>{{ y }}</td>
</tr>
{% endfor %}
{% for z in tabela2 %}
<tr>
<td>{{ z }}<td>
</tr>
{% endfor %}
</table>
Generates this result (decreases the size to fit the image)
And the code that generates this table:
x = PrettyTable(["Horario", "Ligado", "Desligado"])
x.align["Horario"] = "2"
x.align["Ligado"] = "2"
x.align["Desligado"] = "r"
x.padding_width = 1
z=0
while z < len(teste4):
x.add_row([teste4[z], tabela1[z], tabela2[z]])
z = z + 1
print (x)
EDIT
As mentioned in the comments I changed the views to pass a method and the generated table also went wrong, follow code and image
x = PrettyTable(["Horario", "Ligado", "Desligado"])
x.align["Horario"] = "2"
x.align["Ligado"] = "2"
x.align["Desligado"] = "r"
x.padding_width = 1
z=0
while z < len(teste4):
x.add_row([teste4[z], tabela1[z], tabela2[z]])
z = z + 1
print (x)
passar = x.get_html_string()
with the html being Table:{{ pass }}
The structure of your table in HTML is quite wrong. You are inserting elements
<tr>
within elements<td>
, who are already inside<tr>
. In the table, you always define one row at a time, that is, for each<tr>
you will have one or more<td>
and this element can’t had<tr>
within.– Woss
Yes I have done with the right structure, but the result comes out worse than this in the question, as incredible as it looks with this structure is where I got the result more like what I want, but I arranged the question with the right structure
– guilherme
As commented on in your other question, just use the method
get_html_string
ofPrettyTable
.– Woss
Until now I did not understand how to use this method
– guilherme
He returns a string with all the HTML code of your table, just display.
– Woss
Out of curiosity, why do you have two accounts, this and this, on the site? Created a new by mistake?
– Woss
tried here and returned wrong, I will edit the question with the method and your return, on the two accounts, I use one on each pc, when I created one did not remember that I had in the other, I spent time not using
– guilherme
And if you do
{{ passar|safe }}
?– Woss
opa, ai worked out, thank you, just a doubt, has as I leave the fields of the table more spaced between them?
– guilherme