This page explains how to code a simple Flask application.
Basic programming knowledge in Python
Basic Flask knowledge
Comfortable using a terminal
Before using Flask, we need to install it. Open a terminal and type:
$ pip install Flask
Create a new file hello.py with the following content:
from flask import Flaskapp = Flask(__name__)@app.route('/')def hello():return f'Hello from Flask!'
Once the file is saved, let's start the app:
$ # Set up the DEBUG environment$ # (Unix/Mac) export FLASK_ENV=development$ # (Windows) set FLASK_ENV=development$ # (Powershell) $env:FLASK_ENV = "development"$$ flask run$ # Visit the app in browser: http://127.0.0.1:5000/
By visiting the app in the browser we should see "Hello from Flask" message.