0
0
Flaskframework~15 mins

Why routing is Flask's core - See It in Action

Choose your learning style9 modes available
Why routing is Flask's core
📖 Scenario: You are building a simple web app using Flask. The app needs to show different messages on different web pages. To do this, you must tell Flask which URL should show which message. This is called routing.Think of routing like a mail system. Each URL is an address, and Flask delivers the right message to that address.
🎯 Goal: Build a Flask app that uses routing to show different messages on two web pages: the home page and an about page.
📋 What You'll Learn
Create a Flask app instance
Define a route for the home page ('/') that returns 'Welcome to the Home Page!'
Define a route for the about page ('/about') that returns 'This is the About Page.'
Run the Flask app
💡 Why This Matters
🌍 Real World
Web apps need routing to show different pages and content based on the URL users visit.
💼 Career
Understanding routing is essential for backend web developers working with Flask or similar frameworks.
Progress0 / 4 steps
1
Create the Flask app instance
Write the code to import Flask from the flask package and create a Flask app instance called app.
Flask
Need a hint?

Use from flask import Flask and then app = Flask(__name__).

2
Add a route for the home page
Add a route decorator @app.route('/') above a function called home that returns the string 'Welcome to the Home Page!'.
Flask
Need a hint?

Use @app.route('/') and define def home(): that returns the welcome string.

3
Add a route for the about page
Add a route decorator @app.route('/about') above a function called about that returns the string 'This is the About Page.'.
Flask
Need a hint?

Use @app.route('/about') and define def about(): that returns the about string.

4
Run the Flask app
Add the code to run the Flask app by checking if __name__ == '__main__' and then calling app.run().
Flask
Need a hint?

Use the standard Python check if __name__ == '__main__': and call app.run() inside it.