from flask import request
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Order Form</title>
</head>
<body>
<h2>Complete the order form</h2>
<form method="POST" action ="process/">
Your name: <br/>
<input type="text" name="yourname" />
<br/>
Address: <br/>
<input type="text" name="youraddress" />
<br/>
Phone number: <br/>
<input type="text" name="phone" />
<br/>
<hr/>
Choose Product :<br/>
<select name="product">
<option>Garri</option>
<option>Fufu</option>
<option>Akara</option>
</select>
<br/>
Quality order: <br/>
<input type="number" name="qty" required />
<br/>
<input type="submit" name="Order Now"/>
</form>
</body>
</html>
from flask import request
# import the three classes from flask
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/order')
def order():
return render_template('order.html')
@app.route('/process/', methods=['POST'])
def process():
if request.method == 'POST':
#collect the data using the form element name
yourname = request.form['yourname']
youraddress = request.form['youraddress']
phone = request.form['phone']
product = request.form['product']
qty = request.form['qty']
#calculate the total cost of order
if product == "Garri":
price = 500
elif product == "Fufu":
price = 100
elif product == "Akara":
price = 700
total_cost=price * int(qty)
msg = (f"You ordered for {qty} {product} and each cost {price}. Therefore the total cost {total_cost}. Thank you")
return render_template('process.html', name=yourname, message=msg)
if __name__ == '__main__':
app.run(debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Order Process</title>
</head>
<body>
<h2>Order Process</h2>
<h3>{{name}} Thank you for your order</h3>
Orde detail:
<hr/>
{{message}}
</body>
</html>
No Comment yet!