FLASK
FLASK
list_carts = []
total_cost = 0
@app.route('/')
def index():
return render_template('index.html')
@app.route('/contact_us.html')
def contact_us():
return render_template('contact_us.html')
@app.route('/product.html')
def product():
return render_template('product.html')
@app.route('/carts', methods=['POST'])
def carts():
cost = request.form.get(f'cost{i}')
qty = request.form.get(f'qty{i}')
# Only process items that have a valid menu, cost, and quantity greater than 0
try:
cost = float(cost)
qty = int(qty)
if qty > 0:
total_cost += subtotal
except ValueError:
continue
if not list_carts:
total_cost = 0
# Render the template after processing all items
if _name_ == '_main_':
app.run(debug=True)
--------------------------------------------------------------------------------------------------------------------
@app.route('/')
def index():
return render_template('index.html')
@app.route('/contact_us.html')
def contact_us():
return render_template('contact_us.html')
@app.route('/menu.html')
def menu():
return render_template('menu.html')
@app.route('/carts', methods=['POST'])
def carts():
name = request.form.get(f'name{i}')
cost = request.form.get(f'cost{i}')
qty = request.form.get(f'qty{i}')
# Only process items that have a valid name, cost, and quantity
try:
cost = float(cost)
qty = int(qty)
except ValueError:
continue
if __name__ == '__main__':
app.run(debug=True)