Build an HTML Form That Posts
Create a form whose action targets a route.
Build an HTML Form That Posts is a free Flask Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Flask Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Forms Matter
An HTML form is how a browser collects typed input and hands it to your server. It is the front door for almost every user action. 📝
The form Element
Everything starts with a form tag. The browser bundles whatever fields live inside it and sends them together when the user submits.
<form>
<!-- fields go here -->
</form>Point It With action
The action attribute names the URL that receives the data. Leave it empty to post back to the same page the form lives on.
<form action="/signup">Choose the method
Set method to post so the values travel in the request body, not the URL. That keeps form data tidy and out of browser history.
<form action="/signup" method="post">Name Every Field
Each input needs a name attribute. That name becomes the key Flask uses to find the value on the server side.
<input type="text" name="username">Add a Submit Button
A submit button triggers the send. Clicking it tells the browser to gather the named fields and fire the request to your action URL.
<button type="submit">Sign up</button>Match the Route Methods
The receiving route must allow POST. List it in methods, or Flask answers with a 405 and your form data never lands.
@app.route("/signup", methods=["GET", "POST"])
def signup():
...Read Values From request.form
On the server, posted fields live in request.form, a dict-like object keyed by each input name you defined in the HTML.
username = request.form["username"]Serve the Form on GET
When the request is a GET, just render the page that shows the empty form so users have something to fill out.
if request.method == "GET":
return render_template("signup.html")Handle the POST Branch
When the method is POST, read the fields and act on them. One view can both show the form and process the submission.
if request.method == "POST":
name = request.form["username"]A Complete Mini Form
Put it together: a form that posts to /signup and a view that greets the user. That is the full round trip in a few lines.
@app.route("/signup", methods=["GET", "POST"])
def signup():
if request.method == "POST":
return "Hi " + request.form["username"]
return render_template("signup.html")Quick Check
Let us confirm what makes a form actually post.
Recap: Posting Forms
You built a form with an action and post method, named your fields, allowed POST on the route, and read values from request.form. 🎉
Frequently asked questions
Is the “Build an HTML Form That Posts” lesson free?
Yes — the full text of “Build an HTML Form That Posts” is free to read here on the web, and the Flask Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Flask Academy course, upgrade to CoddyKit PRO.
What will I learn in “Build an HTML Form That Posts”?
Create a form whose action targets a route. You practise Flask Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Flask Academy?
No prior experience is required. Flask Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Build an HTML Form That Posts” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Flask Academy lesson?
Yes. Every Flask Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Build an HTML Form That Posts
- Read and Default Query Parameters
- Validate Required Fields by Hand
- Redirect After Post (PRG Pattern)