0
0
Flaskframework~30 mins

Route decorator (@app.route) in Flask - Mini Project: Build & Apply

Choose your learning style9 modes available
Building a Simple Flask Webpage with @app.route
📖 Scenario: You are creating a small web application using Flask. You want to show a welcome message on the homepage.
🎯 Goal: Build a Flask app that shows 'Welcome to Flask!' when you visit the homepage URL.
📋 What You'll Learn
Create a Flask app instance named app
Use the @app.route decorator to define the homepage route '/'
Define a function called home that returns the string 'Welcome to Flask!'
Run the Flask app with debug mode enabled
💡 Why This Matters
🌍 Real World
Web developers use Flask and the @app.route decorator to create web pages and APIs that respond to different URLs.
💼 Career
Understanding routing in Flask is essential for backend web development jobs that build Python web applications.
Progress0 / 4 steps
1
Create the Flask app instance
Import Flask from the flask module and create a Flask app instance called app.
Flask
Need a hint?

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

2
Add the route decorator for homepage
Use the @app.route decorator with the route '/' to define the homepage route.
Flask
Need a hint?

Write @app.route('/') just before the function that handles the homepage.

3
Define the homepage function
Define a function called home that returns the string 'Welcome to Flask!'.
Flask
Need a hint?

Define def home(): and return the welcome string inside it.

4
Run the Flask app
Add the code to run the Flask app with debug mode enabled by calling app.run(debug=True) inside the if __name__ == '__main__': block.
Flask
Need a hint?

Use the standard Python entry point check and call app.run(debug=True) inside it.