【问题标题】:Issue with display formatting multiple forms in one template in Django在 Django 的一个模板中显示格式化多个表单的问题
【发布时间】:2012-06-21 00:49:08
【问题描述】:

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

这是我的模板的样子:

<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

我该怎么做?

页面来源:

【问题讨论】:

  • 页面源渲染后是什么样子的?你需要.as_tables 吗?
  • @jozzas 我添加了页面源
  • 看看 twitter bootstrap 和它的网格布局

标签: python html django django-forms django-templates


【解决方案1】:

想通了,这就是我必须做的:

    <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>

【讨论】:

    猜你喜欢
    • 2010-10-06
    • 2020-07-09
    • 1970-01-01
    • 2017-02-03
    • 2018-09-24
    • 1970-01-01
    • 2016-01-11
    • 2012-10-16
    • 2011-10-11
    相关资源
    最近更新 更多