Flask Sample project that provides an integration of SQLAlchemy ORM on top of a simple Flask Codebase. This project might help beginners to code a real
project on top of Flask. For newcomers, Flask is a lightweight web application framework written in Python. By using a database in our project, we can have a persistent data layer that can be reused and updated according to application requirements.
STATUS: @WIP (work in progress)
Features
- Simple Flask codebase built with
best-practices
in mind - DBMS:
SQLite
Storage - DB Tools:
SQLAlchemy
ORM,Flask-Migrate
(schema migrations) - Permissive MIT License - allows unlimited copies for hobby and commercial products
- Free support via Github and Discord.
Implementation @Todo list
- Add
SQLAlchemy
ORM to therequirements.txt
- SqlAlchemy - v1.4.5
- Flask-SQLAlchemy - v2.5.1
Update codebase
to useSQLAlchemy
- Define a
new model
Populate
the new table withnew data
- Visualize the information on dashboard
- Use a
migration
to update the model (add new field)- Integrate/Use Flask-Migrate v2.7.0
- Use the new information on dashboard
Links
- Atlantis Lite Flask - A full-featured Flask starter
- Atlantis Lite Flask - Demo - LIVE Deployment
$ # Clone the sources
$ git clone https://github.com/app-generator/flask-database-sample.git
$ cd flask-database-sample
$
$ # Virtualenv modules installation (Unix based systems)
$ virtualenv env
$ source env/bin/activate
$
$ # Virtualenv modules installation (Windows based systems)
$ # virtualenv env
$ # .\env\Scripts\activate
$
$ # Install requirements
$ pip3 install -r requirements.txt
$
$ # Set the FLASK_APP environment variable
$ (Unix/Mac) export FLASK_APP=run.py
$ (Windows) set FLASK_APP=run.py
$ (Powershell) $env:FLASK_APP = ".\run.py"
$
$ # Set up the DEBUG environment
$ # (Unix/Mac) export FLASK_ENV=development
$ # (Windows) set FLASK_ENV=development
$ # (Powershell) $env:FLASK_ENV = "development"
$
$ # Run the Jinja Template
$ # --host=0.0.0.0 - expose the app on all network interfaces (default 127.0.0.1)
$ # --port=5000 - specify the app port (default 5000)
$ flask run --host=0.0.0.0 --port=5000
$
$ # Access the UI in browser: http://127.0.0.1:5000/
The project has a simple structure, represented as bellow:
< PROJECT ROOT >
|
|-- app/__init__.py
|-- app/
| |-- static/
| | |-- <css, JS, images> # CSS files, Javascripts files
| |
| |-- templates/
| | |
| | |-- includes/ # Page chunks, components
| | | |
| | | |-- navigation.html # Top bar
| | | |-- sidebar.html # Left sidebar
| | | |-- scripts.html # JS scripts common to all pages
| | | |-- footer.html # The common footer
| | |
| | |-- layouts/ # App Layouts (the master pages)
| | | |
| | | |-- base.html # Used by common pages like index, UI
| | | |-- base-fullscreen.html # Used by auth pages (login, register)
| | |
| | index.html # The default page
| | login.html # Auth Login Page
| | register.html # Auth Registration Page
| | page-404.html # Error 404 page (page not found)
| | page-500.html # Error 500 page (server error)
| | *.html # All other pages provided by the UI Kit
|
|-- requirements.txt
|
|-- run.py
|
|-- ************************************************************************
The project comes with a basic configuration for Docker, Gunicorn, and Waitress.
Docker execution
The steps to start the template using Docker:
Get the code
$ git clone https://github.com/app-generator/flask-database-sample.git
$ cd flask-database-sample
Start the app in Docker
$ sudo docker-compose pull && sudo docker-compose build && sudo docker-compose up -d
Visit http://localhost:5005
in your browser. The app should be up & running.
- Flask Framework - The official website
Flask Database Sample - Open-source sample provided by AppSeed App Generator.