Code a simple app In Flask
How To code a simple Flask Application
This page explains how to code a simple Flask application.
​

Prerequisites

    Basic programming knowledge in Python
    Basic Flask knowledge
    Comfortable using a terminal
​

A minimal app

Before using Flask, we need to install it. Open a terminal and type:
1
$ pip install Flask
Copied!
Create a new file hello.py with the following content:
1
from flask import Flask
2
​
3
app = Flask(__name__)
4
​
5
@app.route('/')
6
def hello():
7
return f'Hello from Flask!'
Copied!
Once the file is saved, let's start the app:
1
$ # Set up the DEBUG environment
2
$ # (Unix/Mac) export FLASK_ENV=development
3
$ # (Windows) set FLASK_ENV=development
4
$ # (Powershell) $env:FLASK_ENV = "development"
5
$
6
$ flask run
7
$ # Visit the app in browser: http://127.0.0.1:5000/
Copied!
By visiting the app in the browser we should see "Hello from Flask" message.
​
Last modified 5mo ago