votr-flask

An educational demonstration CRUD SQL voting web app built with [Flask]

About

votr-flask demonstrates using [Flask] and [MySQL] to make a database management app. It is made for educational purposes only, and is not intended to exemplify production-ready software. Specifically, app.py contains nearly all the back-end logic for this application for ease of reading.

Dev Environment Setup

After you have cloned this repo to your local environment, do the following:

  1. Install pyenv if not installed: [pyenv][https://github.com/pyenv/pyenv]

  2. Install Python version 3.10.2 and use it:

pyenv version 3.10.2
pyenv local 3.10.2
  1. Install [Poetry] for Python dependency management

  2. Install Python dependencies

Do:

poetry install
  1. Set Flask variables:
export FLASK_ENV=development
export FLASK_DEBUG=1
  1. Set up database:

Install MySQL: https://dev.mysql.com/

Create a MySQL user:

  • username: root
  • password: no password

Create a MySQL database with the following parameters:

  • port: 3306
  • database name: votr_flask

Run set_up_db.sql to create the necessary tables and add sample data.

Running locally

Do:

poetry shell
flask run

You should see the following in your terminal:

 * Serving Flask app 'app' (lazy loading)
 * Environment: development
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 126-263-310

Navigate to the URL provided and you should see the app home page.

Reset DB

The following command will reset the database by dropping tables and re-creating them, then seeding them with sample data.

flask reset-db

Deployment to Heroku with new dev changes

Set up your Heroku instance with the necessary env variables.

Update the lockfile with:

poetry lock --no-update

Freeze requirements with:

poetry export -f requirements.txt --output requirements.txt

Test the Heroku deploy locally with:

heroku local

Verify that the app works locally.

Then do:

git push heroku main

Open Source Credits & Acknowledgements

Thanks to all the open source projects that are used as primary dependencies in this project, including:

Python

Database & SQL

Javascript

Design & HTML & CSS Styling

Production Web Server