无法从HTML表单获取输入

时间:2019-07-23 14:36:31

标签: python django

我想在Django中创建一个webapp,将pdf中的订单转换为excel文件。为了更加灵活,我想从pdf检索文本并将其传递到HTML页面上的表格以进行编辑。如果everythig没问题,那么我想从输入数据中下载Excel文件。 有几个输入(取决于有序的pdf中有多少行),我想将其全部传递给我的应用程序。但是下面的代码不起作用。我仅有的结果是按钮的令牌和值。

print(request.POST.keys())
print(request.POST['Submit'])
print(request.body)
<form action="extract_pdf" method="post">
        {% csrf_token %}
        <div class="row">
            <div class="col-sm">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <label class="input-group-text" for="inputGroupSelect01">Company ID</label>
                    </div>
                    <select class="custom-select" id="inputGroupSelect01">
                        {% for item in company %}
                        <option value="a">{{item.1}}</option>
                        {% endfor %}
                    </select>
                </div>
            </div>
            <div class="col-sm">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="company_name">Company Name</span>
                    </div>
                    <input type="text" class="form-control" id="name" aria-describedby="basic-addon3" value="{{info.company_name}}">
                </div>
            </div>
            <div class="col-sm">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="order_no">Order Number</span>
                    </div>
                    <input type="text" class="form-control" id="ord_no" aria-describedby="basic-addon3" value="{{info.order_number}}">
                </div>
            </div>
        </div>
        {% for row in rows %}
        <div class="row">
            <div class="col-sm">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="item_nr">Jeeves Code</span>
                    </div>
                    <input type="text" class="form-control" id="item" aria-describedby="basic-addon3" value="{{row.item}}">
                </div>
            </div>
            <div class="col-sm">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="item_qty">Item Qty</span>
                    </div>
                    <input type="text" class="form-control" id="qty" aria-describedby="basic-addon3" value="{{row.qty}}">
                </div>
            </div>
            <div class="col-sm">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="item_price">Item price</span>
                    </div>
                    <input type="text" class="form-control" id="price" aria-describedby="basic-addon3" value="{{row.price}}">
                </div>
            </div>
        </div>
        {% endfor %}
        <input type="submit" class="btn btn-success" value="Download" name="Submit" />
    </form>

请帮助我查找代码中的错误:)

1 个答案:

答案 0 :(得分:0)

您需要命名您的输入。 request.POST是来自POST数据的键值对的字典,如果不提供输入名称,django将无法建立这种关系并在request.POST中提供数据。希望这会有所帮助!