Flask/Gunicorn

From XPUB & Lens-Based wiki
Revision as of 15:42, 8 April 2026 by Manetta (talk | contribs) (Created page with "''A subpage of Flask'' ==How to install a Flask application using Gunicorn?== First install gunicorn and python-dotenv: $ uv pip3 install gunicorn python-dotenv And then make or change the following files: '''Makefile''' <pre> include .env export default: local local: @flask --app ${APPLICATION_NAME} --debug run server: @SCRIPT_NAME=${APPLICATION_ROOT} gunicorn -b localhost:${PORTNUMBER} --reload ${APPLICATION_NAME}:app </pre> '''.env''' <...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A subpage of Flask

How to install a Flask application using Gunicorn?

First install gunicorn and python-dotenv:

$ uv pip3 install gunicorn python-dotenv

And then make or change the following files:

Makefile

include .env
export

default: local

local:
        @flask --app ${APPLICATION_NAME} --debug run

server:
        @SCRIPT_NAME=${APPLICATION_ROOT} gunicorn -b localhost:${PORTNUMBER} --reload ${APPLICATION_NAME}:app

.env

APPLICATION_NAME=observations
APPLICATION_ROOT=/sergio/manettasobservations
PORTNUMBER=5100

settings.py

import os
from dotenv import main

# Load environment variables from the .env file
main.load_dotenv()

# Bind them to Python variables
APPLICATION_ROOT = os.environ.get('APPLICATION_ROOT', '/')
PORTNUMBER = int(os.environ.get('PORTNUMBER', 5000))

app.py

# load the settings of the applicaiton
# (to handle the routing correctly)
app.config.from_pyfile('settings.py')

nginx

# overlap flask application
location ^~ /overlap/static/ {
    alias /var/www/html/breadbrick/SI21/week5/static/;
    autoindex on;
}

location ^~ /overlap/ {
    proxy_pass http://localhost:5000/breadcube/overlap/;
}