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>
答案 0 :(得分:1)
如果您已将表格传递给请求中的表单,则只需使用Django模板标记:
<table>
<tr>{{ table.row_1 }}</tr>
<tr>
<td>{{ table.row_2_col_1 }}</td>
<td>{{ table.row_2_col_2 }}</td>
</tr>