简体   繁体   中英

How to make a dynamic table in HTML using python

I want to make a dynamic table using HTML. In my website the user needs to enter number of row and number of columns and I want to create a table in HTML in the size that the user input for me.

I am using python 2.7 and Jinja.

How can I do it?

I'm not sure how your application is setup so I can't give you the exact way of how to handle the user input in Python. Anyway you need to create an iterable object and then send it to Jinja.

Then you need to iterate over it in Jinja:

<table>
{% for row in table %}
<tr>
    {% if loop.index == 1 %}
        {% for cell in row %}
            <th>{{cell}}</th>
        {% endfor %}
    {% else %}
        {% for cell in row %}
            <td>{{cell}}</td>
        {% endfor %}
    {% endif %}
</tr>
{% endfor %}
</table>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM