This time we will cover the steps to create a new development environment for Python and the Flask web development framework. We will create our first Flask application and we will learn how to configure custom routing rules inside Flask.
Flask is a micro framework used for website and Web API development. Being a micro framework means it has a simple core and it is easily extendable. You will see it is very easy and fast to create applications using Flask.
Now, let’s get started.
Make sure you already installed python. If not, go to python.org to install it. Then using
pip to install Flask.
pip install flask
Create a python file
In your working directory, create a python file. I name it app.py (any filenames also ok). And write this snippet inside it.
from flask import Flaskapp = Flask(__name__)# This is the custom [email protected]('/')def index(): return 'Halo Flask.'@app.route('/about')def about(): return 'About Me'app.run('0.0.0.0', debug=True)
Now, you can run your first flask application using:
It will run at your localhost using port 5000 as defult port.
Check it in your browser:
Done. It’s easy and simple, isn’t it?
Next, we will cover to make web API with Flask. Stay Tune!