Return Strings, HTML, and Status Codes
Send different bodies and set HTTP status.
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>"All lessons in this course
- The @app.route Decorator
- How a Request Becomes a Response
- Return Strings, HTML, and Status Codes
- Multiple Routes in One App