从django模板提交通过POST传递其他数据

问题描述 投票:1回答:1

使用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中提供这个?

django python-3.x django-templates django-views
1个回答
2
投票

你需要提到每个name attributeinput tags

<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" name="{{product.id}}_jan" class="user-action"></td>
   <td><input type="text" id="{{product.id}}_feb" data-id="{{product.id}}_feb" name="{{product.id}}_feb" class="user-action"></td>
   <td><input type="text" id="{{product.id}}_mar" data-id="{{product.id}}_mar" name="{{product.id}}_mar" class="user-action"></td>
   <td><input type="text" id="{{product.id}}_total" data-id="{{product.id}}_total" name= "{{product.id}}_total" readonly="readonly" class="total-quantity"></td>
 </tr>
     <input type="hidden" value="{{product.weight}}" id="{{product.id}}_weight" name="{{product.id}}_weight" >
     <input type="hidden" value="{{product.is_winter}}" id="{{product.id}}_winter" name="{{product.id}}_winter">
{% endfor %}

或者提供适合您目的的任何名称

© www.soinside.com 2019 - 2024. All rights reserved.