Skip to content

Repository files navigation

FlaskDash starter app v3.0

Screenshot

This code base serves as a starting point for writing your next Flask application.

It's based on the awesome work of Ling Thio and includes the open source CoreUI v5 admin Bootstrap 5 theme and a number of enhancements to the base Flask starter app including basic user management and a separate view file for API code.

Code characteristics

  • Tested on Python 3.13
  • Well organized directories with lots of comments
    • app
      • commands
      • controllers
      • models
      • static
      • templates
    • tests
  • Includes test framework (pytest and tox)
  • Includes database migration framework (Flask-Migrate / alembic)
  • Sends error emails to admins for unhandled exceptions

What's new in v3.0

  • Upgraded from CoreUI v4 (Bootstrap 4) to CoreUI v5 (Bootstrap 5)
  • Replaced jQuery with vanilla JavaScript throughout
  • Replaced Highcharts with Chart.js v4 for dashboard charts
  • Replaced font-based icon libraries (Font Awesome, Simple Line Icons) with CoreUI SVG icon sprites (free.svg, brand.svg, flag.svg)
  • Replaced perfect-scrollbar with SimpleBar
  • Dark/light/auto color mode support via CoreUI v5's built-in theme switcher
  • Removed all legacy static assets (Bootstrap 4, jQuery, Highcharts, Popper.js, Pace, old icon fonts)
  • Breadcrumbs now rendered in the sticky header via a Jinja2 breadcrumb block
  • Flash message dismissal now uses data-coreui-dismiss="alert" (no JavaScript required)

Setting up a development environment

We assume that you have git and Python 3.13 installed.

# Clone the code repository into ~/dev/my_app
mkdir -p ~/dev
cd ~/dev
git clone https://github.com/twintechlabs/flaskdash.git my_app

# Create a virtual environment and activate it
cd ~/dev/my_app
python3.13 -m venv .venv
source .venv/bin/activate

# Install required Python packages
pip install -r requirements.txt

Configuring SMTP

Edit the app/local_settings.py file and set the MAIL_... settings to match your SMTP provider.

You should also set a strong, unique value for SECURITY_PASSWORD_SALT in local_settings.py. Do not use the default value in production.

Initializing the Database

# Create DB tables and populate the roles and users tables
flask init-db

Running the app (development)

# Start the Flask development web server
flask run

Point your web browser to http://localhost:5000/

You can make use of the following seed users:

  • email member@example.com with password Password1
  • email admin@example.com with password Password1

Running the app (production)

Gunicorn is included in requirements.txt. To run in production:

gunicorn --bind 0.0.0.0:5000 "app:create_app()"

Or use unicorn.py as the entry point:

gunicorn unicorn:app

Database migrations

When you change a model, generate and apply a migration:

flask db migrate -m "Description of change"
flask db upgrade

If you are upgrading an existing database from v1.x, you must run a migration to add the fs_uniquifier column required by Flask-Security-Too:

flask db migrate -m "Add fs_uniquifier to users"
flask db upgrade

Running the automated tests

pytest tests/

# With coverage:
pytest tests/ --cov=app

Using Server-side Sessions

FlaskDash has Flask-Session built in, configured to use the SQLAlchemy backend by default. The sessions table is created automatically by flask init-db.

You can change the backend in local_settings.py by setting SESSION_TYPE to redis, filesystem, or other supported backends.

Usage example:

session['key'] = 'value'
val = session.get('key', 'not set')

Trouble shooting

If you make changes to models and run into DB schema issues during development, delete the SQLite DB file app.sqlite and re-run flask init-db.

Key dependencies

Authors

  • Matt Hogan - matt AT twintechlabs DOT io
  • Ling Thio -- ling.thio AT gmail DOT com

Flask-User-starter-app was used as a starting point for this code repository.

About

Flask starter app featuring CoreUI and the FlaskUser module.

Topics

Resources

Stars

113 stars

Watchers

11 watching

Forks

Releases

Packages

Used by

Contributors

Languages