/ Python

Creating Your First Flask Application


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.

Install flask
Make sure you already installed python. If not, go to python.org to install it.

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 Flask

app = Flask(__name__)

# This is the custom routes.
@app.route('/')
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:

python app.py

It will run at your localhost using port 5000 as defult port.

Check it in your browser:

http://localhost:5000

Done. It's easy and simple, isn't it?

Next, we will cover to make web API with Flask. Stay Tune!

Creating Your First Flask Application
Share this