Python Flask Micro-Tutorial 1: Installation and Hello World
Welcome to the first micro-tutorial in our series on Python Flask! In this tutorial, we will cover the installation of Flask and how to create a simple “Hello World” application using Flask.
Installation
To install Flask, you first need to have Python installed on your computer. You can download Python from the official website and follow the installation instructions. Once you have Python installed, you can use the pip
package manager to install Flask. Open a terminal or command prompt and run the following command:
pip install Flask
This will install Flask and all of its dependencies on your system.
Hello World
Now that you have Flask installed, let’s create a simple “Hello World” application. Create a new Python file, for example app.py
, and add the following code:
“`python
from flask import Flask
app = Flask(__name__)
@app.route(‘/’)
def hello_world():
return ‘Hello, World!’
if __name__ == ‘__main__’:
app.run()
“`
In this code, we first import the Flask class from the flask
module. We then create a new instance of the Flask class and define a route for the home page ('/'
). The hello_world()
function is called when a user visits the home page, and it simply returns the string 'Hello, World!'
. Finally, we start the Flask development server with app.run()
.
To run the Flask application, save the file and run the following command in the terminal or command prompt:
python app.py
You should see a message indicating that the Flask development server is running. Open a web browser and navigate to http://127.0.0.1:5000/
to see your “Hello World” message.
Congratulations, you have successfully installed Flask and created a simple web application! Stay tuned for more tutorials on Python Flask to learn how to build more complex web applications.
At 0:52 , the command is 'pip install flask' not 'pip install pip' . Whoops, my bad!