D
D
Dmitry2018-03-30 12:48:33
Django
Dmitry, 2018-03-30 12:48:33

How to create an html table using Python?

Greetings, the bottom line is that there is a parser that merges the necessary information into csv, but it’s inconvenient to view it on a mobile phone, and the encoding flies because the parser ignores encoding errors, I got the idea to file it all in stml, but then I blunted the stml
code:

<table style="border:2px black solid">
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>    
</table>

how to make python write the result to the cells, each in its own then create a new line, fill it in, and so on

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2018-03-30
@ipatov_dn

>>> from jinja2 import Template
>>> template = Template("""
... <table style="border:2px black solid">
...    <tr>
...      {% for item in my_array %}
...      <td>{{item}}</td>
...      {% endfor %}
...    </tr>
... </table>""")
>>> my_array = range(10)
>>> my_array
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> print(template.render(my_array=my_array))

<table style="border:2px black solid">
   <tr>
     <td>0</td>
     <td>1</td>
     <td>2</td>
     <td>3</td>
     <td>4</td>
     <td>5</td>
     <td>6</td>
     <td>7</td>
     <td>8</td>
     <td>9</td>
   </tr>
</table>
>>>

With the rest - you will understand, I hope?

L
longclaps, 2018-03-30
@longclaps

So that the python writes the result to the cells, each in its own, then creates a new line, fills it in, and so on,

you need to learn python or hire someone who knows it.
Since this is your 36th python question, you should consider the second option.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question