V
V
Villian_Os2020-11-25 09:53:10
Django
Villian_Os, 2020-11-25 09:53:10

How to present an input form on a website in tabular form using the django templating language?

I'm creating textarea input forms with variable names name0 name1 name2 and so on, displaying them in a table in one line

<table class="table table-bordered mt-4">
                <tr>
                    {%for name in inputs%}
                    <th><textarea class="form-control" name={{name}} id="1"
                                 placeholder="Поле ввода" rows="3" required></textarea>
                    </th>
                    {% endfor %}
                </tr>
            </table>

and I receive the data on the server as it should.
But how to make it so that every second or third input field wraps to a new line, as in the picture?
5fbdff2c5af0e120187699.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-11-25
@Villian_Os

about constructions of the form

{% if forloop.counter|divisibleby:"2" %}<tr>{% endif %}
<td><td>
{% if not forloop.counter|divisibleby:"2" %}</tr>{% endif %}

{% cycle 'row' '' as row silent %}
{% if row %}<tr>{% endif %}
<td><td>
{% if not row %}</tr>{% endif %}

do not forget about if there is an odd number, then close tr also for the last one

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question