嗨,我有一个文字输入框,如:
<div class="form-group">SCAN ORDERS :
<input id="scan_order" name="scan_order" type="text" placeholder="Scan" class="form-control" autocomplete="off">
</div>
它位于已经定义了动作的表单中。我想将这个文本框与条形码扫描仪一起使用。那么如何将它与django视图绑定?
在此框中扫描数据时,我想将该数据传递到我的django视图。
我的views.py:
def packOrders(request):
oid_list = []
form = forms.OrderItems(request.POST or None)
api = APIMethods()
if request.method == 'POST' and 'download_labels' in request.POST:
list_of_ids = request.POST.getlist('po')
for id in list_of_ids:
oid_list.append(id)
api.downloadShippingLabels(oid_list)
file = open('shipping_labels.pdf', 'rb')
response = HttpResponse(file, content_type='application/pdf')
response['Content-Disposition'] = "attachment; filename=shipping_labels.pdf"
os.system('rm shipping_labels.pdf')
return response
elif request.method == 'POST' and 'mark_dispatch' in request.POST:
list_of_ids = request.POST.getlist('po')
for id in list_of_ids:
oid_list.append(id)
api.dispatchOrders(oid_list)
return HttpResponseRedirect(reverse('orders'))
html表格:
<form action="{% url 'packOrders' %}" method="POST">
{% csrf_token %}
<div class="panel-body">
<div class="pad-btm form-inline">
<div class="row">
<div class="col-sm-6 table-toolbar-left">
<button name="download_labels" id="download_labels" class="btn btn-purple btn-labeled fa">Download Labels</button>
<button name="mark_dispatch" id="mark_dispatch" class="btn btn-purple btn-labeled fa">Mark Ready To Dispatch</button>
</div>
<div class="col-sm-6 table-toolbar-right">
<div class="form-group">SCAN ORDERS :
<input name="scan_order" id="scan_order" type="text" placeholder="Scan" class="form-control" autocomplete="off">
</div>
</div>
</div>
</div>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th><input type="checkbox" onClick="toggle(this, 'po')"></th>
<th>Order Id</th>
<th>Channel</th>
<th>Dispatch By Date</th>
<th>Amount</th>
<th>Status</th>
<th>Tracking Number</th>
</tr>
</thead>
<tbody>
{% for oid,oiid,dbd,stts,tp in pack_orders %}
<tr>
<td><input type="checkbox" name="po" value="{{oiid}}"></td>
<td>
<div>
<a class="btn-link" href="#">{{oid}}</a>
</div>
<div>
{{oiid}}
</div>
</td>
<td>Flipkart</td>
<td><span class="text-muted"><i class="fa fa-clock-o"></i> {{dbd}}</span></td>
<td>{{tp}}</td>
<td>
{{stts}}
</td>
<td>-</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</form>
我想要类似的东西:
<input name="scan_order" id="scan_order" type="text" placeholder="Scan" class="form-control" autocomplete="off">
和观点:
elif request.method == 'POST' and 'scan_order' in request.POST:
## Do Something
问题是:我可以使用现有表格吗?或者是否有另一种方法将数据传递给我的views.py?