0

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?

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.