Flask: handling form input

18-minute lesson · module-webapps-04

You are previewing this course as a guest

Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.

Sign in

Flask: handling form input

18-minute lesson · module-webapps-04

  • Accept POST requests in a view function with the methods argument.
  • Read submitted form fields from request.form by name.
  • Render an HTML template with render_template and pass data into it.
  • Use redirect with url_for to follow a POST with a fresh GET.

Source attribution

Status: adapted

How to Think Like a Computer Scientist: Interactive Edition source · Web Applications / Input For A Flask Web Application / Web Applications With A User Interface

Adaptation notes. Read-along lesson; no graded coding step because Flask runs a server the Pyodide sandbox cannot host. Code (view functions, a Jinja template, redirect) is for reading and local running. The greeting-form example is ours; prose is original.

License notes. Original chapter is GNU FDL 1.3 (Brad Miller, David Ranum, and the upstream Elkner/Downey/Meyers text). No verbatim text reproduced. Flask is BSD-licensed; only API names are referenced.