0
0
Flaskframework~30 mins

Response object creation in Flask - Mini Project: Build & Apply

Choose your learning style9 modes available
Response Object Creation in Flask
📖 Scenario: You are building a simple web server using Flask. You want to send custom responses to users when they visit certain pages.
🎯 Goal: Create a Flask app that returns a custom response object with specific content and status code.
📋 What You'll Learn
Create a Flask app instance named app
Define a route /hello that returns a response object
The response object must contain the text 'Hello, Flask!'
Set the HTTP status code of the response to 200
💡 Why This Matters
🌍 Real World
Web servers often need to send custom responses with specific content and status codes to clients.
💼 Career
Understanding how to create and customize response objects is essential for backend web development with Flask.
Progress0 / 4 steps
1
Create the Flask app instance
Create a Flask app instance named app by importing Flask from flask and initializing it.
Flask
Need a hint?

Use app = Flask(__name__) to create the app instance.

2
Define a route for /hello
Define a route /hello using @app.route('/hello') and create a function named hello that will handle requests to this route.
Flask
Need a hint?

Use the @app.route('/hello') decorator and define a function hello().

3
Create a response object with text
Inside the hello function, import Response from flask and create a response object with the text 'Hello, Flask!'.
Flask
Need a hint?

Use return Response('Hello, Flask!') inside the function.

4
Set the HTTP status code to 200
Modify the response object creation in the hello function to set the HTTP status code to 200 explicitly.
Flask
Need a hint?

Pass status=200 as a parameter to Response.