Flask Datta Able
Open-source Flask Starter coded on top Datta Able design (Free Version).
Flask Admin Dashboard generated by the AppSeed platform on top of Datta Able design (free version) crafted by CodedThemes.
Version: v1.0.8 - release date
2022-06-13
Built with Datta Able Generator
UI Kit: Datta Able (free version)
DB Tools: SQLAlchemy ORM, Flask-Migrate (schema migrations)Session-Based authentication (via flask_login), Forms validation
Deployment scripts: Docker, Gunicorn/Nginx
Links
π Datta Able Flask - Product page
π Datta Able Flask - LIVE deployment
π Support (Email and LIVE on Discord) for
registered users.
β¨ Environment
To use the starter, Python3 should be installed properly in the workstation. If you are not sure if Python is installed, please open a terminal and type python --version. Here is the full list with dependencies and tools required to build the app:
Python3 - the programming language used to code the app
GIT - used to clone the source code from the Github repository
Basic development tools (g++ compiler, python development libraries ..etc) used by Python to compile the app dependencies in your environment.
(Optional)
Docker- a popular virtualization software
β¨ Start the app in Docker
π Step 1 - Download the code from the GH repository (using
GIT)
$ # Get the code
$ git clone https://github.com/app-generator/flask-datta-able.git
$ cd flask-datta-ableπ Step 2 - Start the APP in
Docker
$ docker-compose up --build Visit http://localhost:5085 in your browser. The app should be up & running.
β¨ Manual Build
Download the code
$ # Get the code
$ git clone https://github.com/app-generator/flask-datta-able.git
$ cd flask-datta-ableπ Set Up for Unix, MacOS
Unix, MacOSInstall modules via
VENV
$ virtualenv env
$ source env/bin/activate
$ pip3 install -r requirements.txtSet Up Flask Environment
$ export FLASK_APP=run.py
$ export FLASK_ENV=developmentStart the app
$ flask runAt this point, the app runs at http://127.0.0.1:5000/.
π Set Up for Windows
WindowsInstall modules via
VENV(windows)
$ virtualenv env
$ .\env\Scripts\activate
$ pip3 install -r requirements.txtSet Up Flask Environment
$ # CMD
$ set FLASK_APP=run.py
$ set FLASK_ENV=development
$
$ # Powershell
$ $env:FLASK_APP = ".\run.py"
$ $env:FLASK_ENV = "development"Start the app
$ flask runAt this point, the app runs at http://127.0.0.1:5000/.
β¨ Manage App Users
UsersBy default, the starter is not provided with users.
π Create Users
By default, the app redirects guest users to authenticate. In order to access the private pages, follow this set up:
Start the app via
flask runAccess the
registrationpage and create a new user:http://127.0.0.1:5000/register
Access the
sign inpage and authenticatehttp://127.0.0.1:5000/login\
β¨ Codebase structure
The project is coded using a simple and intuitive structure presented below:
< PROJECT ROOT >
|
|-- apps/
| |
| |-- home/ # A simple app that serve HTML files
| | |-- routes.py # Define app routes
| |
| |-- authentication/ # Handles auth routes (login and register)
| | |-- routes.py # Define authentication routes
| | |-- models.py # Defines models
| | |-- forms.py # Define auth forms (login and register)
| |
| |-- static/
| | |-- <css, JS, images> # CSS files, Javascripts files
| |
| |-- templates/ # Templates used to render pages
| | |-- includes/ # HTML chunks and components
| | | |-- navigation.html # Top menu component
| | | |-- sidebar.html # Sidebar component
| | | |-- footer.html # App Footer
| | | |-- scripts.html # Scripts common to all pages
| | |
| | |-- layouts/ # Master pages
| | | |-- base-fullscreen.html # Used by Authentication pages
| | | |-- base.html # Used by common pages
| | |
| | |-- accounts/ # Authentication pages
| | | |-- login.html # Login page
| | | |-- register.html # Register page
| | |
| | |-- home/ # UI Kit Pages
| | |-- index.html # Index page
| | |-- 404-page.html # 404 page
| | |-- *.html # All other pages
| |
| config.py # Set up the app
| __init__.py # Initialize the app
|
|-- requirements.txt # App Dependencies
|
|-- .env # Inject Configuration via Environment
|-- run.py # Start the app - WSGI gateway
|
|-- ************************************************************************β¨ Application Bootstrap Flow
The entry point of the project is the run.py file where the project configuration is bundled. The most important files that make the project functional are listed below:
run.pyis the application entry pointread the
Debugflag from.envimport the
dbobject fromappspackageimport the
create_apphelper fromapps
Flaskapplication is built bycreate_appIf
Debug=True- SQLite is used (development mode)If
Debug=False- MySql is used (production mode)
Configuration
is defined in
apps/config.py
β¨ How the Flask App object is constructed
Flask App object is constructedThe file that constructs the core features of our application is apps/__init__.py. The most important steps are listed below:
Invokes SQLAlchemy to build the
dbobject.Using
SQLAlchemywe can manage the database information with ease
Invokes LoginManager to build the
login_managerobject.login_managermanage the authentication layer (login, logout, register)
Defines
create_apphelper that does the following:create the
Flaskapp objectinjects
dbandlogin_managerobjectsloads the
configurationregister
default blueprints:authentication- handles the authentication routeshome- serve all the pages saved in theapps/templates/homefolder
initialize the database
db.create_all()- create all tables
β¨ Application Blueprints
The codebase is built using a modular design that uses blueprints. By default, the project comes with a two blueprints
π Authentication Blueprint
Definition:
apps/authentication. The core files:
__init__.py- defines the Blueprint objectmodels.py- defines theUsersmodelforms.py- defines theLoginandRegistrationformsutils.py- helpers used to hass and verify the passwordroutes- manages the authentication routes:loginregisterlogout
π Home Blueprint
This module returns all pages saved in the templates/home directory to authenticated users. In case a page is not found, a generic page is returned using a 404 HTTP error status.
β¨ UI Assets and Templates
The project comes with a modern UI fully migrated and usable with Django Template Engine.
π Page Templates
All pages and components are saved inside the apps/templates directory. Here are the standard directories:
templates/layouts: UI masterpagestemplates/includes: UI components (used across multiple pages)templates/accounts: login & registration pagetemplates/home: all other pages served via a generic routing byapps/homeapp
< PROJECT ROOT >
|
|-- apps/
| |
| |-- home/ # A simple app that serve HTML files
| |-- authentication/ # Handles auth routes (login and register)
| |
| |-- static/
| | |-- <css, JS, images> # CSS files, Javascripts files
| |
| |-- templates/ # Templates used to render pages
| |-- includes/ # HTML chunks and components
| | |-- navigation.html # Top menu component
| | |-- footer.html # App Footer
| | |-- scripts.html # Scripts common to all pages
| |
| |-- layouts/ # Master pages
| | |-- base.html # Used by common pages
| |
| |-- accounts/ # Authentication pages
| | |-- login.html # Login page
| | |-- register.html # Register page
| |
| |-- home/ # UI Kit Pages
| |-- index.html # Index page
| |-- page-404.html # 404 page
| |-- *.html # All other pages
|
|-- ************************************************************************π Static Assets
The static assets used by the project (JS, CSS, images) are saved inside the apps/static/assets folder. This path can be customized with ease via ASSETS_ROOT variable saved in the .env file.
How it works
.envdefines theASSETS_ROOTvariableapps/config.pyread the value ofASSETS_ROOTand defaults to/static/assetsif not found:
# content of apps/config.py (truncated content)
ASSETS_ROOT = os.getenv('ASSETS_ROOT', '/static/assets') All pages and components use the
config.ASSETS_ROOTvariable. Here is a sample extracted fromtemplates/layouts/base.html:
<head>
<!-- Source Code -->
<link rel="stylesheet" href="{{ config.ASSETS_ROOT }}/css/style.css">
<!-- RUNTIME -->
<link rel="stylesheet" href="/static/assets/css/style.css">At runtime, the href property is resolved to /static/assets/css/style.css based on the value saved in the .env file:
# No Slash at the end
ASSETS_ROOT=/static/assets⨠Customisation
π Set up the MySql Database
Note: Make sure your Mysql server is properly installed and accessible.
Step 1 - Create the MySql Database to be used by the app
Create a new MySqldatabaseCreate a new userand assign full privilegies (read/write)
Step 2 - Install
flask_mysqldbpackage
$ pip install flask_mysqldbStep 3 - Edit the
.envto match your MySql DB credentials. Make sureDEBUGis set toFalse.
DB_ENGINE:mysqlDB_NAME: default value =appseed_dbDB_HOST: default value =localhostDB_PORT: default value =3306DB_USERNAME: default value =appseed_db_usrDB_PASS: default value =pass
Here is a sample:
# .env sample
DEBUG=False # False enables the MySql Persistence
DB_ENGINE=mysql # Database Driver
DB_NAME=appseed_db # Database Name
DB_USERNAME=appseed_db_usr # Database User
DB_PASS=STRONG_PASS_HERE # Password
DB_HOST=localhost # Database HOST, default is localhost
DB_PORT=3306 # MySql port, default = 3306 At this point, the app should use MySql for the persistence layer.
π Static Assets for production
productionAs explained in the Static Assets section, the assets are managed via:
apps/static/assets- the folder whereJS,CSS, andimagesfiles are savedASSETS_ROOT- environment variable, that defaults to/static/assetsif not defined
In production, the contents of the apps/static/assets files should be copied to an external (public) directory and the ASSETS_ROOT environment variable updated accordingly.
For instance, if the static files are copied to https://cdn.your-server.com/datta-able-assets, the .env file should be updated as below:
# No Slash at the end
ASSETS_ROOT=https://cdn.your-server.com/datta-able-assetsπ Where to go from here
π Access the support page in case something is missing
π Use Datta Able Generator to generate a new project
π Check-out the PREMIUM version, Flask Datta Able PRO (
live demo) for more features and improved UIβ
Bootstrap 5versionβ More pages & components
β
Dark-Modeβ Priority on support
β Flask Datta Able PRO -
product page

Last updated
Was this helpful?