samedi 8 avril 2017

Pass dynamic form data to view

i have a form which renders a form element multiple times with a for-loop. I would like to access the specific form data in my view, but not sure how to do so.

in my html i render the following:

<form action=“” method=“post”>
    
    
</form>

as this is a CRUD app, items in ‘menu’ are dynamically created and have a unique id from the database. i need to associate a user-inputted quantity to that specific item id.

in my view, i would like to do the following:

@app.route(‘/order’, methods=[‘GET’,’POST’])
def order():
    menu = MenuItems.query.all()
    form = OrderForm()

    if form.validate_on_submit():
        quantities = form.quantity.data (##### how do I access the user-inputted quantity per item.id here??? for example… to show that item.id(1) has the quantity (5) inputted by the user?)
        print(quantities) 

    return render_template(‘order.html’, menu=menu, form=form)




Aucun commentaire:

Enregistrer un commentaire