liveBook · Manning

Flask

As explained in A Pythonic Adventure: From Python basics to a working web app

Flask is a lightweight Python web application framework.

Flask is a lightweight Python framework for creating web applications. It lets a Python program run locally, respond to browser URLs, and grow into a practical project such as a coffee-shop menu. section 10.1 section 10.0

A first Flask application connects a few friendly pieces:

  • Run the starter application in Mu’s Web mode and open the local address http://127.0.0.1:5000/ in a browser. section 10.0
  • Map a URL to a Python function with a route, such as /hello/<name> or /order. section 10.0
  • Receive submitted HTML-form data through request.form, then render a template containing the result. section 10.0

A coffee-shop order

An HTML form offers Coffee and Decaf. Its action targets /order with the POST method. Flask checks the request method, reads the selected drink, and renders a thank-you page showing the order and a New order button. section 10.0

Listing 10.4 The function to process an order
@app.route('/order', methods=('GET', 'POST'))   #1
def order():
    if request.method == 'POST':                #2
        drink = request.form['drink']           #3
        print("Drink: ", drink)                 #4
 
    return render_template("forms.html")        #5

Browse the order-processing function to see routing, POST detection, form access, and template rendering together. section 10.0

How A Pythonic Adventure: From Python basics to a working web app covers it

How deep it goes
Explains starter setup, routes, forms, requests, and templates through working examples, without descending into framework internals.
Examples
Uses a local greeting route and a coffee-shop menu that submits Coffee or Decaf and prints the selected drink.
What it assumes
Assumes basic Python practice while teaching web-application setup, browser URLs, HTML forms, and Flask concepts incrementally.
What you can do after
Build it from scratch as a small Flask application that serves pages, accepts form input, and displays processed results.
How it connects
Connects Python with web applications, HTML forms, URLs, HTTP request methods, templates, and the Mu editor.

Also explained in

Compare how 4 books explain Flask →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of A Pythonic Adventure: From Python basics to a working web app. The section links point to the parts of the book it draws on.