0
class MyForm(forms.Form):
  row_1 = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES)
  row_2_col_1 = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES)
  row_2_col_2 = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES)

  def render_form(request):
    form = MyForm()
    # render form

我的模板应该是什么,以便最终的 html 类似于

<table>
<tr> row_1 field.. </tr>
<tr>
  <td> row_2_col_1 field.. </td>
  <td> row_2_col_2 field.. </td>
</tr>
4

1 回答 1

1

如果您已将表格传递给请求中的表单,则只需使用 Django 模板标记:

<table>
<tr>{{ table.row_1 }}</tr>
<tr>
  <td>{{ table.row_2_col_1 }}</td>
  <td>{{ table.row_2_col_2 }}</td>
</tr>
于 2012-09-27T13:40:29.033 回答