git clone https://github.com/biobricks/openfoundry-api.git
cd openfoundry-api
virtualenv venv
source venv/bin/activate
venv\Scripts\activate
pip install flask python-dotenv flask-wtf flask-sqlalchemy flask-migrate flask-login flask-moment
flask run
The flask environment is configured using variables found in .env files.
This is the configuration for the flask application environment.
default: /openfoundry.py
description: The entry point script to be executed on flask run
.
default: development
description: The server environment.
default: 1
description: Enables the debugging console.
The application configuration is loaded from a class found at config.py.
Example: Gmail
Note for this example to work, gmail requires insecure apps to be turned on here.
export MAIL_SERVER=smtp.googlemail.com
export MAIL_PORT=587
export MAIL_USE_TLS=1
export MAIL_USERNAME=<your-gmail-username>
export MAIL_PASSWORD=<your-gmail-password>
set MAIL_SERVER=smtp.googlemail.com
set MAIL_PORT=587
set MAIL_USE_TLS=1
set MAIL_USERNAME=<your-gmail-username>
set MAIL_PASSWORD=<your-gmail-password>
Example: Comment Class
Add model to models.py:
from datetime import datetime
from app import db
# other classes
class Comment(db.Model):
id = db.Column(db.Integer, primary_key=True)
body = db.Column(db.String(140))
timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
user_id = db.Column(db.Integer, db.ForeignKey(user.id))
def __repr__(self):
return '<Comment {}>'.format(self.body)
Since we changed our database models, we changed our database structure and need to generate a migration. We added a comments table, that will be our migration message:
flask db migrate -m "comments table"
Generating a migration does not alter the database. We have to run the migration:
flask db upgrade
flask db init
flask db migrate -m "my migration message"
flask db upgrade
flask db downgrade
flask shell
flask run