Project structure: Tutorial series
python main.py
- Login:
/auth/login
- Logout:
/auth/logout
- Profile:
/auth/profile
- Register:
/auth/register
- Upload:
/file/upload
The python packages needed to run the webapp can be installed with:
pip install -r requirements.txt
flask-migrate is an extension based on Alembic, a migrations tool for SQLAlchemy. The following instructions use it to first add a migrations
folder at the root of the project, then to create a new migration and finally apply it:
- Define environment variable:
export FLASK_APP=main.py
flask db init
flask db migrate -m "message"
flask db upgrade
An instance
folder needs to be created at the root of the project to contain database access credentials. For that, instance/config.py
will have to contain:
import os
# needed by csrf field in wtforms & user passwords)
SECRET_KEY = os.urandom(32)
# database access
SQLALCHEMY_DATABASE_URI = "postgresql://<user>:<password>@<host>/<database>"
If the password of the user used to login to pgadmin4 was forgotten, it can be reset with:
ALTER USER user_name WITH PASSWORD 'new_password';
The files uploaded through this web application should also be placed inside the instance
folder (e.g. inside a photos subdirectory).
The docker image was deployed on the docker-hub. The following commands were used to build and tag the image, and deploy it to the hub:
docker build -t <hub-user>/<repo-name> .
docker login
docker push <hub-user>/<repo-name>
To download the image on another machine:
docker run <hub-user>/<repo-name>