【发布时间】:2018-08-13 21:13:08
【问题描述】:
使用Django模板显示input text的表格。
但在view 中,只有来自该表的输入出现在request.POST 中。 POST 中不提供动态创建的输入。
test.html
<form class="form-horizontal" method="post" enctype='multipart/form-data' id="subscription-form">
....
....
<tbody class="draggable-column">
{% for product in products %}
<tr>
<td class="hidden-xs">{{forloop.counter}}</td>
<td class="hidden-xs">{{product.title}}</td>
<td class="hidden-xs">{{product.weight}}</td>
<td class="" >{{product.yearly_consumption}}</td>
<td><input type="text" id="{{product.id}}_jan" data-id="{{product.id}}_jan" class="user-action"></td>
<td><input type="text" id="{{product.id}}_feb" data-id="{{product.id}}_feb" class="user-action"></td>
<td><input type="text" id="{{product.id}}_mar" data-id="{{product.id}}_mar" class="user-action"></td>
......
......
<td><input type="text" id="{{product.id}}_total" data-id="{{product.id}}_total" readonly="readonly" class="total-quantity"></td>
</tr>
<input type="hidden" value="{{product.weight}}" id="{{product.id}}_weight">
<input type="hidden" value="{{product.is_winter}}" id="{{product.id}}_winter">
{% endfor %}
</tbody>
....
....
</form>
此表输入在 django 视图的 POST 中不可用。
如何在 POST 中提供此功能?
【问题讨论】:
-
您的所有输入都没有
name属性,因此它们不会包含在POST数据中。您需要为所有这些指定一个name属性。
标签: django python-3.x django-templates django-views