A web application gives people an interactive program in a browser. Instead of using an iPad as a paper notepad for coffee orders, a small coffee shop can offer a menu, accept a choice, and show the submitted order on a web page. Start small: one useful screen is already a real application. section 1.0 section 10.0
A running application listens at an address such as http://127.0.0.1:5000/. Open that URL in a browser to see it. In a Python setup, Flask supplies the application structure, while routes connect addresses such as /order to Python functions that decide which page to return. section 10.0
A first order-taking web application can work in a simple loop:
- Show an HTML form with menu choices and a Submit button. section 10.0
- Send the form to an /order route with a POST request. section 10.0
- Read the submitted values in Python and pass them to a template. section 10.0 section 11.0
- Display a friendly order-confirmation page, with a button for another order. section 10.0
A coffee menu that remembers orders
A fuller menu asks for a customer name, drink, flavor, and topping. The route gathers those fields into a dictionary, adds it to an orders list, and saves the list as orders.json. When the application starts again, it can load earlier orders before accepting new ones. That turns a nice-looking form into a useful shop tool. section 11.0 section 11.0
A web application is meant to keep running so it can respond whenever someone sends a request. This makes it different from a short text-mode program that finishes and stops. For an order system, staying available means the next customer can use the menu without restarting the program. section 11.0
Listing 10.1 The first menu form with two options
<html>
<body>
<form>
<select>
<option>Coffee</option>
<option>Decaf</option>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html>
Inspect the smallest useful interface: a select menu inside a form and a Submit button. Change the options, run the application, and see how the browser presents your choices. section 10.0







