如何将多个选择从Jinja传递到路由功能?

时间:2019-01-06 15:47:43

标签: flask jinja2

jinjaflask
如何将选定行的列表从html表传递到路由功能 我通过

将表数据传递到模板
@order_bp.route('/', methods=['GET', 'POST'])
def orders():
    order_form = OrdersForm()
    orders_list = []
    if request.method == 'POST':
        if order_form.cirte_options.data == 1:
            orders_list = admin.models.Order.query.filter(
                cast(admin.models.Order.trans_date, Date) == order_form.orders_date.raw_data[0]). \
                filter_by(trans_type='8', p_code=str(order_form.branches_list.data)
                          , typ=1, canceled=0, delivary_date=None) \
                .join(admin.models.Area).all()
        drivers_list = admin.models.Employee.query.filter_by(job=3, branch=order_form.branches_list.data).all()

        return render_template('orders.html', order_form=order_form, orders_list=orders_list, drivers_list=drivers_list)
    return render_template('orders.html', order_form=order_form)

在模板中,我将其放在table

<form action="{{ url_for('order.assignOrder') }}" method="post">
                        <table class="table">
                            <thead>
                            <tr>
                                <th>Order Number</th>
                                <th>Cust. Name</th>
                                <th>Cust. Address</th>
                                <th>Cust. Number</th>
                                <th>Order Date</th>
                                <th>Dilevary Date</th>
                                <th>Assign To</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for item in orders_list %}

                                <tr>
                                    <td>{{ item.p_code }}{{ item.trans_type }}{{ item.trans_no }}
                                        <input type="hidden" name="order_id" value="{{ item.p_code }}">
                                    </td>

                                    <td>{{ item.cust_name }}</td>
                                    <td>{{ item.area.name  ~ " - " ~ item.sector ~ " - " ~ item.street ~
          " - "~ item.home_no ~" - " ~ (item.floor or '')  ~" - "~ (item.flat or '') }}</td>
                                    <td>{{ item.cust_tele1 }}</td>
                                    <td>{{ item.trans_date.strftime('%Y-%m-%d') }}</td>
                                    <td>{{ item.delivary_date }}</td>
                                    <td>
                                        <input type="checkbox" name="check">
                                </tr>
                            {% endfor %}

                            </tbody>
                        </table>
                    </form>

我必须选择一些行并将其传递到其他路线

@order_bp.route('/ordasg', methods=['GET', 'POST'])
def assignOrder():
    ordd = request.form.getlist('che')
    print(ordd)
    order_form = OrdersForm(request.form)

    return render_template('orders.html', order_form=order_form)

0 个答案:

没有答案