Welcome to the exciting world of Flask, a micro web framework written in Python! In this lesson, we'll guide you through creating your first Flask app. šÆ
Flask is a lightweight and easy-to-use web framework for Python. It allows you to quickly develop web applications without the complexity of larger frameworks. š
Before we dive in, make sure you have:
pip install flaskNow let's create a simple Flask app that serves a "Hello, World!" message.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return "Hello, World!"
if __name__ == '__main__':
app.run(debug=True)š Note: Each Flask app starts with creating a new Flask web server. The __name__ == '__main__' checks if the script is being run directly (not imported as a module) and starts the server.
Save the code above in a file named app.py and run it:
python app.pyNow open your browser and visit http://localhost:5000/. You should see "Hello, World!" displayed. š
In the next part of this tutorial, we'll explore more about Flask routes, handling user inputs, and connecting to databases. Stay tuned! š”
Which command is used to install Flask?