0

我试图在一个模板中显示三个表单。我显示了表格,但是表格一个接一个地列出来。我试图让它们显示在三个单独的列中。

这是我的模板的样子:

<html lang="en">
<head>
    <title>Title</title>
</head>
<body>
    <h1>Header</h1>
    <form action="." method="POST">
    {% csrf_token %}
        <table>
            <tr>
                <th>h1</th>
                <th>h2</th>
                <th>h3</th>
            </tr>
            <tr>
                <td>{{ form1.as_table }}</td>
                <td>{{ form2.as_table }}</td>
                <td>{{ form3.as_table }}</td>
            </tr>
        </table>
        <p><input type="submit" value="Submit"></p>
    </form>
</body>
</html>

当它渲染时,它会显示如下:

h1     h2     h3
form1
form2
form3

我想要这样的东西:

h1     h2     h3
form1  form2  form3

我该怎么做?

页面来源:

在此处输入图像描述

4

1 回答 1

0

Figured it out, this is what I had to do:

    <table>
        <tr>
        <td>
        <table>
            <th>h1</th>
            <td>{{ form1.as_table }}</td>
        </table>
        </td>
        <td>
        <table>
            <th>h2</th>
            <td>{{ form2.as_table }}</td>
        </table>
        </td>
        <td>
        <table>
            <th>h3</th>
            <td>{{ form3.as_table }}</td>
        </table>
        </td>
        </tr>
    </table>
于 2012-06-19T02:52:15.383 回答