This version has been developed following steps in https://flask.palletsprojects.com/en/2.0.x/tutorial/
Create a virtual environment for flask with miniconda:
conda create --name flsk
conda activate flsk
or with venv... in our local machine
python3 -m venv ~/proyectos/flsk
# or python3 -m venv ~/venv/flsk
source ~/proyectos/flsk/bin/activate
## or source ~/proyectos/venv/flsk/bin/activate
or with venv... in the cloud instance within the project/fireveg-webapp folder:
source venv/bin/activate
Check python version
python --version
Update and install modules
pip install --upgrade pip
#/usr/local/opt/python@3.9/bin/python3.9 -m pip install --upgrade pip
pip3 install -U Flask
pip install psycopg2-binary
pip install flask-wtf
pip install folium
pip install pandas
pip install datetime
pip install openpyxl
pip install pillow ipyplot
pip install pyinaturalist
pip install pickle5
pip install flask_migrate flask_cors flask_sqlalchemy
pip3 install python-dotenv
pip3 install sendgrid
Create and initialise directory
mkdir -p ~/proyectos/fireveg/fireveg-webapp
cd ~/proyectos/fireveg/fireveg-webapp
git init
pip freeze > requirements.txt
# conda activate flsk ## or
# source ~/proyectos/venv/flsk/bin/activate
cd ~/proyectos/fireveg/fireveg-webapp
export FLASK_APP=webapp
export FLASK_DEBUG=TRUE
# initialise sqlite database if doesn't exists / old version with sqlite
# [ -e instance/webapp.sqlite ] || flask init-db
# For new authentication system
# Either 'SQLALCHEMY_DATABASE_URI' or 'SQLALCHEMY_BINDS' must be set
# run the webapp
flask run
A database.ini
file must be added to the instance
folder to be able to connect to the postgresql database with the information for the database host, port, database name, user and password.
[aws-lght-sl]
host=...
port=...
database=...
user=...
password=...
First update the pickle files with content for the data entry form:
cd ~/proyectos/fireveg-webapp/webapp
python xlcontent.py
Create a folder for the upload of files:
cd ~/proyectos/fireveg/fireveg-webapp/ ## or
cd ~/proyectos/fireveg-webapp/
mkdir -p instance/uploaded_files/litrev
mkdir -p instance/uploaded_files/fieldform
For the field work proforma, we just copy the file provided by David, since we have not replicated this form in our python scripts:
mv ~/Desktop/FireResponseProforma_20220621\[1\].docx ~/proyectos/fireveg/fireveg-webapp/instance/field-work-proforma.xlsx
For the other data entry and export forms, we can use the app functions below:
cd ~/proyectos/fireveg/fireveg-webapp ## or
cd ~/proyectos/fireveg-webapp/
export FLASK_APP=webapp
export FLASK_DEBUG=TRUE
# export FLASK_ENV=development # deprecated
flask init-dataentry
flask init-data-export
flask init-recordlist-export
There are some difference with function send_file
between Flask version 2.0.2 and 2.2.2 will need to test different virtual environments to see if it is worth upgrading in the deployment or downgrading in the local machine.
pip install gunicorn
cd ~/proyectos/fireveg/fireveg-webapp
gunicorn -w 4 --reload --bind 0.0.0.0:5000 "webapp:create_app()"
https://python-adv-web-apps.readthedocs.io/en/latest/flask.html