Пример #1
0
def add_snack():
    """Renders snack form (GET) or handles snack form submission (POST)"""
    form = AddSnackForm()
    if form.validate_on_submit():
        name = form.name.data
        price = form.price.data
        flash(f"Created new snack: name is {name}, price is ${price}")
        return redirect('/')
    else:
        return render_template("add_snack_form.html", form=form)
Пример #2
0
def add_snack():
    form = AddSnackForm()
    if form.validate_on_submit():
        name = form.name.data
        price = form.price.data
        healthy = form.is_healthy.data
        flash(f'Snack created: name is {name}, price is {price}')
        return redirect('/')

    else:
        return render_template('add-snack-form.html', form=form)
Пример #3
0
def add_snack():
    print(request.form)
    form = AddSnackForm()
    if form.validate_on_submit():
        # is this a post req and is this a valid token
        name = form.name.data
        price = form.price.data
        flash(f"Created new snack: name is {name}, price is ${price}")
        
        return redirect('/')
    else:
        return render_template("add_snack_form.html", form=form)
Пример #4
0
def add_snack():
    """Snack add form; handle adding."""

    form = AddSnackForm()

    if form.validate_on_submit():
        name = form.name.data
        price = form.price.data
        flash(f"Added {name} at {price}")
        return redirect("/")

    else:
        return render_template("add_snack_form.html", form=form)
Пример #5
0
def add_snack():
    #print(request.form)
    form = AddSnackForm()

    if form.validate_on_submit():
        #is this a post request and is the toekn valid?
        data = request.form
        name = form.name.data
        price = form.price.data
        flash(f"created new snack name is {name}, price is ${price}, {data}")
        return redirect('/')
    else:
        return render_template("add_snack_form.html", form=form)
Пример #6
0
def add_snack():
    form = AddSnackForm()

    if form.validate_on_submit():
        #is this a post request AND csrf token is there
        name = form.name.data
        price = form.price.data
        session['name'] = name
        session['price'] = price
        flash(f"New snack created. Name: {name}, price is ${price}")
        return redirect('/')
    else:
        return render_template("add_snack_form.html", form = form)

# @app.route('/yep')
# def noty():
#     name = session.get('name', None)
#     return render_template("yep.html", name = name)
Пример #7
0
def add_snack():
    """Snack add form; handle adding."""

    form = AddSnackForm()

    if form.validate_on_submit():
        name = form.name.data
        price = form.price.data
        quantity = form.quantity.data
        total_price = price * quantity
        is_healthy = form.is_healthy.data
        if is_healthy:
            flash(
                f'Added {name} at ${price} each and a healthy snack. Quantity: {quantity}, total price: ${total_price}'
            )
        else:
            flash(
                f'Added {name} at ${price} and a junkfood snack. Quantity: {quantity}, total price: ${total_price}'
            )
        return redirect('/')
    else:
        return render_template('add_snack_form.html', form=form)
Пример #8
0
def add_snack():
    form = AddSnackForm()
    return render_template("snack_add_form.html", form=form)