research-school-2025/proj/v1-human-readability
Arija A. e18526c4c6
Implement basic auth
Signed-off-by: Arija A. <ari@ari.lt>
2025-12-07 15:48:16 +02:00
..
src Implement basic auth 2025-12-07 15:48:16 +02:00
.editorconfig Init: v1-human-readability 2025-12-07 14:00:29 +02:00
.eslintrc.js Init: v1-human-readability 2025-12-07 14:00:29 +02:00
.gitignore Init: v1-human-readability 2025-12-07 14:00:29 +02:00
.prettierrc Init: v1-human-readability 2025-12-07 14:00:29 +02:00
example.env Init: v1-human-readability 2025-12-07 14:00:29 +02:00
LICENSE Init: v1-human-readability 2025-12-07 14:00:29 +02:00
pyproject.toml Init: v1-human-readability 2025-12-07 14:00:29 +02:00
README.md Init: v1-human-readability 2025-12-07 14:00:29 +02:00
requirements.txt Implement basic auth 2025-12-07 15:48:16 +02:00
tox.ini Init: v1-human-readability 2025-12-07 14:00:29 +02:00

Flask template

Simple flask template

Running

First compile WASM PoW:

cd src/static/js/wasm
./compile.sh
cd ../../../../

Then:

python3 -m venv venv
source venv/bin/activate
source .env  # see example.env
pip install --upgrade -r requirements.txt
cd src
memcached -d
# If you remove migrations/:
# flask db init
# vim migrations/script.py.mako (add import flask_app)
# flask db migrate -m 'Initial migration'
flask db upgrade
flask run

For production use a WSGI server such as Gunicorn:

python3 -m venv venv
source venv/bin/activate
source .env  # see example.env
pip install --upgrade -r requirements.txt
pip install --upgrade gunicorn
cd src
memcached -d
flask db upgrade
python3 -m gunicorn -b 127.0.0.1:12345 -w 4 app:app  # ... Or whatever your configuration is

I don't want a generic flask_app module name

Run python3 rename.py <new_module_name>, for example, python3 rename.py my_app :)

I need custom subcommands

In src/flask_app/__init__.py you can register your custom flask subcommands using click:

import click
import flask


@click.command("hello")
def cmd_hello() -> None:
    """Print hello"""
    print("Hello!")


def create_app(name: str) -> flask.Flask:
    ...

    app: flask.Flask = flask.Flask(name)

    ...

    # Commands

    app.cli.add_command(create_counter)

    ...

    return app

If you have a lot of custom commands it is advised you move your commands to a file called commands.py or alike, then register them as usual using app.cli.add_command. To run these subcommands you would simply do

flask hello

Or whatever your custom subcommand is.

Linting and Formatting

Use the following tools: