An educational demonstration CRUD SQL voting web app built with [Flask]
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.
After you have cloned this repo to your local environment, do the following:
-
Install pyenv if not installed: [pyenv][https://github.com/pyenv/pyenv]
-
Install Python version 3.10.2 and use it:
pyenv version 3.10.2
pyenv local 3.10.2
-
Install [Poetry] for Python dependency management
-
Install Python dependencies
Do:
poetry install
- Set Flask variables:
export FLASK_ENV=development
export FLASK_DEBUG=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.
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.
The following command will reset the database by dropping tables and re-creating them, then seeding them with sample data.
flask reset-db
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
Thanks to all the open source projects that are used as primary dependencies in this project, including:
- [Flask][https://flask.palletsprojects.com/]
- [Poetry][https://python-poetry.org/docs/#installation]
- [WTForms][https://wtforms.readthedocs.io/en/3.0.x/]
- [Flask-WTF][https://flask-wtf.readthedocs.io/]
- [Jinja2][https://jinja2docs.readthedocs.io/en/stable/]
- [python-dotenv][https://saurabh-kumar.com/python-dotenv/]
- [MySQL][https://www.mysql.com/]
- [Flask-SqlAlchemy][https://flask-sqlalchemy.palletsprojects.com/]
- [PyMySQL][https://pymysql.readthedocs.io/en/latest/]
- [List.js][https://listjs.com/]
- [jQuery][https://jquery.com/]
- [Bootswatch][https://bootswatch.com/] - Darkly Theme
- [Material Design][https://materialdesignicons.com/] - check-circle icon
- [Gunicorn][https://gunicorn.org/]