Boilerplate Django Dashboards
Reference codebase used in all Django Dashboards provided by the AppSeed platform
All Django Dashboards generated by AppSeed share the same codebase structure and features:
Reference Codebase - Django Dashboards Boilerplate
SQLite Database, Django Native ORM
Session-Based Authentication, Forms validation
Deployment scripts: Docker, Gunicorn/Nginx
β¨ 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/boilerplate-code-django-dashboard.git
$ cd boilerplate-code-django-dashboardπ 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/boilerplate-code-django-dashboard.git
$ cd boilerplate-code-django-dashboard\
π Set Up for Unix, MacOS
Unix, MacOSInstall modules via
VENV
$ virtualenv env
$ source env/bin/activate
$ pip3 install -r requirements.txtSet Up Database
$ python manage.py makemigrations
$ python manage.py migrateStart the app
$ python manage.py runserverAt this point, the app runs at http://127.0.0.1:8000/.
\
π Set Up for Windows
WindowsInstall modules via
VENV(windows)
$ virtualenv env
$ .\env\Scripts\activate
$ pip3 install -r requirements.txtSet Up Database
$ python manage.py makemigrations
$ python manage.py migrateStart the app
$ python manage.py runserverAt this point, the app runs at http://127.0.0.1:8000/.
\
β¨ Manage App Users
UsersBy default, the starter is not provided with users. To access the private pages and the admin section (reserved for superusers) follow up the next sections.
π Create Superusers
SuperusersTo access the admin section, Django requires superuser privilegies. Let's create a new superuser and access the admin section of the project:
$ python.exe manage.py createsuperuser
>>> Username (leave blank to use 'test'): test
>>> Email address: admin@appseed.us
>>> Password: *******
>>> Password (again): *******
>>> Superuser created successfully.Once the superuser is successfully created, we can access the admin section:
http://localhost:8000/admin/ (make sure you have a / at the end).
\
π Create (Ordinary) 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
python manage.py runserverAccess the
registrationpage and create a new user:http://127.0.0.1:8000/register/
Access the
sign inpage and authenticatehttp://127.0.0.1:8000/login/
\
β¨ Codebase structure
The project is coded using a simple and intuitive structure presented below:
< PROJECT ROOT >
|
|-- core/ # Implements app configuration
| |-- settings.py # Defines Global Settings
| |-- wsgi.py # Start the app in production
| |-- urls.py # Define URLs served by all apps/nodes
|
|-- apps/
| |
| |-- home/ # A simple app that serve HTML files
| | |-- views.py # Serve HTML pages for authenticated users
| | |-- urls.py # Define some super simple routes
| |
| |-- authentication/ # Handles auth routes (login and register)
| | |-- urls.py # Define authentication routes
| | |-- views.py # Handles login and registration
| | |-- 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
| | |-- 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
|
|-- requirements.txt # Development modules - SQLite storage
|
|-- .env # Inject Configuration via Environment
|-- manage.py # Start the app - Django default start script
|
|-- ************************************************************************\
β¨ Application Bootstrap Flow
The entry point of the project is the core.settings.py file where the project configuration is bundled. The most important files that make the project functional are listed below:
manage.py(saved in the root of the project) loadscore/settings.pycore/settings.py:Loads the
.envfile (dynamic configuration)Loads the project routing:
core.urls.py
Defines the
templatesdirectoryapps/templates
Defines the
INSTALLED_APPSsectionapps.home- custom app that serve all pages
If the
DB_ENGINEvariable is not present in the environmentSQLitepersistence is used
If the
DB_ENGINEis presentThe DB URI is built dynamically for
MySqlorPostgreSQL.
\
β¨ Project Routing
The core file that bundles together all routing rules is core/urls.py.
The home application being a generic router that serves all pages defined in the templates/home directory, should be the last rule defined in the urlpatterns.
NOTE: all new apps, should be included above
apps.home.urlsgeneric rule.
urlpatterns = [
path('admin/', admin.site.urls), # Django admin route
path("", include("apps.authentication.urls")), # Auth routes - login / register
# ADD NEW Routes HERE
# Leave `Home.Urls` as last the last line
path("", include("apps.home.urls"))
]\
β¨ 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 >
|
|-- core/ # Implements app configuration
|-- 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_ROOTvariablecore/settings.pyread the value ofASSETS_ROOTand defaults to/static/assetsif not found:
# content of core/settings.py (truncated content)
ASSETS_ROOT = os.getenv('ASSETS_ROOT', '/static/assets') All pages and components use the
ASSETS_ROOTvariable. Here is a sample extracted fromtemplates/layouts/base.html:
<head>
<!-- Source Code -->
<link rel="stylesheet" href="{{ 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\
β¨ Default Apps
The codebase comes with two simple apps that handle the authentication and serve all pages saved in the apps/templates/home directory.
π Authentication App
This default app defined in apps/authentication handles the authentication routes login, register. The most important files that make the authentication usable, are listed below:
forms.py- defines the Login, Registration formsviews.py- implements the login, registration flowroutes.py- map routing rules over the viewsmodels.py- EMPTY fileThe extended user model is NOT provided
π Home App
This app 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.
\
β¨ 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
mysqlclientpackage
$ pip install mysqlclientStep 3 - Edit the
.envto match your MySql DB credentials. Make sureDB_ENGINEis set tomysql.
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
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.
π Adding a new app
The existing codebase can be extended with ease with new apps and features. Here are the steps that create a new application named polls.
Create a new app using
startappcommand (make sure you are in the root of the project)
$ python manage.py startapp pollsWrite a simple view for the new app - Edit
polls/views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello! This is the polls APP index.")Create urls.py inside the
pollsdirectory
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]Update project routing -
core/urls.pyfile:
urlpatterns = [
path('admin/', admin.site.urls),
path("", include("apps.authentication.urls")),
# ADD NEW Routes HERE
path('polls/', include('polls.urls')), # <-- NEW
# Leave `Home.Urls` as last the last line
path("", include("apps.home.urls"))
]Enable the new app - Update
core/settings.pyfile:
... (truncated content)
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls', # <-- NEW
'apps.home'
]
... (truncated content)Start the project and access the project in the browser:
http://localhost:8000/polls/

\
π 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 the App Generator and build a new project
Last updated
Was this helpful?