A simple flask app with web interface
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Ryan Reed c771f1018a Adding overview 6 years ago
app Initial commit 6 years ago
migrations Initial commit 6 years ago
.flaskenv Initial commit 6 years ago
.gitignore Initial commit 6 years ago
README.md Adding overview 6 years ago
config.py Initial commit 6 years ago
requirements.txt Initial commit 6 years ago
run.py Initial commit 6 years ago

README.md

Table of Contents

Overview

This repo contains a simple flasks application. The application provides a simple web GUI with routes and a template.

Setting up the environment

Install the requirements

pip install -r requirements.txt

Setup the environment variables

The following can be added to a .env file in the foot of this directory as well

APP_ENVIRONMENT="PROD"
SECRET_KEY="myverysecretkey"
DATABASE_URL="sqlite:///app.db"

Database

Workflow for updating database (new table/field/etc)

  1. Export the flask app: export FLASK_APP=stockpyle.py
  2. Create/modify class for table in app/models.py
  3. Create migration script: flask db migrate -m "<class/table> table"
  4. Commit migration script to repo (for upgrading other environments)
  5. Make the changes to the database: flask db upgrade

Initial DB Setup for the app

flask db upgrade

Working with the database

Adding to the database

u = User(username='john', email='john@example.com')
u.set_password('password')
db.session.add(u)

u = User(username='susan', email='susan@example.com')
u.set_password('password')
db.session.add(u)

db.session.commit()

Querying the database

# get user
u = User.query.get(1)
u
#<User john>

# get all users in reverse alphabetical order
User.query.order_by(User.username.desc()).all()
#[<User susan>, <User john>]

Clear out the tables

users = User.query.all()
for u in users:
    db.session.delete(u)

db.session.commit()