0Pricing
Flask Academy · Lesson

Return Strings, HTML, and Status Codes

Send different bodies and set HTTP status.

Return Strings, HTML, and Status Codes is a free Flask Academy lesson on CoddyKit — lesson 3 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.

Returning a Plain String

The simplest response is a plain string. Flask sends it straight to the browser as the page body with a 200 status.

@app.route("/")
def home():
    return "Hello"

Strings Can Hold HTML

Your string can contain real HTML tags. The browser parses them, so returning a heading renders as a styled title, not as raw text.

return "<h1>Welcome</h1>"

Inline HTML Gets Messy

Writing big pages as one giant string gets unreadable fast. It works for tiny snippets, but real pages belong in template files later.

The Default Status

When you return just a body, Flask assumes a 200 status, meaning OK. You only set a code when the result is not a plain success.

Return a Status Code

Return a tuple of body and number to set the status. Here a missing item answers with a 404 instead of the default 200.

return "Not found", 404

Common Success Codes

Use 201 when you create something new and 200 for a normal read. The right code tells clients exactly what happened.

return "Created", 201

Common Error Codes

Use 400 for bad input, 404 for missing pages, and 500 when your own code crashes. Each number has a clear, agreed meaning.

Add Headers Too

Extend the tuple with a third part, a dict of headers, when you need to control things like the content type of the reply.

return "OK", 200, {"X-App": "demo"}

make_response for Control

For finer control, build a make_response object. You can set its status and headers step by step before returning it.

resp = make_response("Hi")
resp.status_code = 202

Strings Are Auto-Wrapped

Even a bare string gets wrapped in a full response behind the scenes. Flask handles the boilerplate so your views stay short.

Pick the Honest Code

Always return a truthful status. Sending 200 for an error confuses clients and hides real bugs from anyone using your app.

Quick Check

Pick the response that sets a custom status.

Recap

You can return plain text, HTML, or a tuple with a status and headers. Honest status codes keep your responses clear and trustworthy. ✅

Frequently asked questions

Is the “Return Strings, HTML, and Status Codes” lesson free?

Yes — the full text of “Return Strings, HTML, and Status Codes” 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 “Return Strings, HTML, and Status Codes”?

Send different bodies and set HTTP status. 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 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Return Strings, HTML, and Status Codes” 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

  1. The @app.route Decorator
  2. How a Request Becomes a Response
  3. Return Strings, HTML, and Status Codes
  4. Multiple Routes in One App
← Back to Flask Academy