DEV Community

Cover image for Flask Dashboard - Gradient Able Design

Posted on • Updated on

Flask Dashboard - Gradient Able Design

Hello coders,

This article aims to help beginners to get starting with Flask, the super-popular Python framework, by building and coding simple tasks on top of an open-source starter: Flask Gradient Able. The project can be downloaded directly from Github and used in commercial projects (MIT License).

For newcomers, Flask is a lightweight web application framework written in Python. Sometimes classified as a microframework, Flask provides a lightweight codebase that can be easily extended to become an API, a simple web app, or a complex eCommerce platform.

Flask Dashboard Gradientable - Open-source admin dashboard coded in Flask.

This Flask starter being coded on top of a nice Ui Kit and released under the MIT license can be used for unlimited hobby & commercial products. Besides this, the code-base is clean and easy to digest by the main audience: beginners. Other features:

  • UI Kit: Gradient Able Dashboard (Free Version)
  • Modular codebase coded with Blueprints
  • SQLite/PostgreSQL database, ORM, Alembic for migrations
  • Session-based authentication, basic form validation
  • Deployment scripts: Docker, Gunicorn / Nginx

In case you like this simple Flask starter, we can build it using a terminal and a few basic commands. The app is coded in Python3 and to have a successful build we need a Python3 interpreter properly installed in our workstation. If you are not sure about it, please open your preferred terminal and type:

$ python -V
Python 3.7.2 <--- All good
Enter fullscreen mode Exit fullscreen mode

If the python version check returns a 3.x version, we're all good.

Let's clone the source code

As mentioned, the app is published on Github and we can clone the code using GIT command tool or simply download the ZIP archive.

$ # Get the code
$ git clone
$ cd flask-dashboard-gradientable
Enter fullscreen mode Exit fullscreen mode

After cloning/copying the sources we need to install the app dependencies listed in the requirements.txt file.

$ # Install modules - SQLite Database
$ pip3 install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

The next step is to set the value for FLASK_APP variable and we're all set.

$ # Set the FLASK_APP environment variable
$ (Unix/Mac) export
$ (Windows) set
$ (Powershell) $env:FLASK_APP = ".\"
$ # Start the application (development mode)
$ # --host= - expose the app on all network interfaces (default
$ # --port=5000    - specify the app port (default 5000)  
$ flask run --host= --port=5000
$ # Access the dashboard in browser:
Enter fullscreen mode Exit fullscreen mode

If all goes well, by visiting the dashboard in browser we should the login screen:

Flask Dashboard Gradientable - The login page.

By default, this Flask starter is not provisioned with default users and to pass the authentication and access the private pages we need to create a new user first by using the registration page.

After login, we should be able to access the dashboard pages:

Main Dashboard Page

Flask Dashboard Gradientable - Main dashboard page.

Google Maps page

Flask Dashboard Gradientable - Main dashboard page.

UI Tables

Flask Dashboard Gradientable - UI Tables page.

Code-base structure

The project is coded using blueprints, app factory pattern, dual configuration profile (development and production) and an intuitive structure presented bellow:

   |-- app/                      # Implements app logic
   |    |-- base/                # Base Blueprint - handles the authentication
   |    |-- home/                # Home Blueprint - serve UI Kit pages
   |    |
   |               # Initialize the app
   |-- requirements.txt          # Development modules - SQLite storage
   |-- requirements-mysql.txt    # Production modules  - Mysql DMBS
   |-- requirements-pqsql.txt    # Production modules  - PostgreSql DMBS
   |-- .env                      # Inject Configuration via Environment
   |--                 # Set up the app
   |--                    # Start the app - WSGI gateway
   |-- ************************************************************************
Enter fullscreen mode Exit fullscreen mode

How app starts

  • loads the .env file
  • Initialize the app using the specified profile: Debug or Production
    • If env.DEBUG is set to True the SQLite storage is used
    • If env.DEBUG is set to False the specified DB driver is used (MySql, PostgreSQL)
  • Call the app factory method create_app defined in app/
  • Redirect the guest users to Login page
  • Unlock the pages served by HOME blueprint for authenticated users

App Deployment

The starter comes equipped with a basic deployment enhancement for Docker. To start the app in a dockerized container we need to type a single line in the terminal (commands provided for Linux distros):

$ sudo docker-compose pull && sudo docker-compose build && sudo docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

If all goes well, we should see the app running in the browser by visiting http://localhost:5005.

Thanks for reading! For more resources, feel free to access:

Top comments (3)

andalinux profile image
InformáticoDeGuardia 👨‍💻

Thanks @sm0ke for sharing this project 👍🏻

I've programmed with Flask before but I can improve my code using your example as a guide.

I only need to know how do you recommend including oAuth (using Google account) as loging into the app.

Maybe an idea for a next article? 😉 (If not some code would be appreciated 😅👍🏻)

sm0ke profile image

That's a super idea. Noted!
& thanks for reading!

andalinux profile image
InformáticoDeGuardia 👨‍💻

Nice to see you like the idea, Sm0ke
It will be great know how do you implement that blueprint with Google oAuth 👍
And if you explain how to save authorization token to use your web until we log out it could be wonderful 😉😇