2012-06-19 36 views
0

我试图在一个模板中显示三种表单。我有表格显示,但表格连续列出。我试图让他们在三个单独的列中显示。在Django的一个模板中显示格式化多个表单的问题

这是我的模板是什么样子:

<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 

如何我会那样做吗?

页来源:

enter image description here

+0

什么是网页的源文件看起来像它的渲染后?你需要'.as_table'吗? – jozzas

+0

@jozzas我添加了页面源 –

+0

看看twitter bootstrap,它的网格布局 –

回答

0

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

<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> 
相关问题