Boilerplate Jinja
Template boilerplate code used by AppSeed to generate simple starters coded in Flask.
Jinja is basically an engine used to generate HTML or XML returned to the user via an HTTP response. For those who have not been exposed to a templating language before, such languages essentially contain variables as well as some programming logic, which when evaluated (or rendered into HTML) are replaced with actual values.
Features:
  • UI Ready: the starter contains a production-ready design
  • Render Engine: Flask / Jinja2​
  • Deployment scripts: Docker, Gunicorn/Nginx, HEROKU
Links
​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)
1
$ # Get the code
2
$ git clone https://github.com/app-generator/boilerplate-code-jinja.git
3
$ cd boilerplate-code-jinja
Copied!
πŸ‘‰ Step 2 - Start the APP in Docker
1
$ docker-compose up --build
Copied!
Visit http://localhost:5085 in your browser. The app should be up & running.

✨ Manual Build

Download the code
1
$ # Get the code
2
$ git clone https://github.com/app-generator/boilerplate-code-jinja.git
3
$ cd boilerplate-code-jinja
Copied!

πŸ‘‰ Set Up for Unix, MacOS

Install modules via VENV
1
$ virtualenv env
2
$ source env/bin/activate
3
$ pip3 install -r requirements.txt
Copied!
Set Up Flask Environment
1
$ export FLASK_APP=run.py
2
$ export FLASK_ENV=development
Copied!
Start the app
1
$ flask run
Copied!
At this point, the app runs at http://127.0.0.1:5000/.

πŸ‘‰ Set Up for Windows

Install modules via VENV (windows)
1
$ virtualenv env
2
$ .\env\Scripts\activate
3
$ pip3 install -r requirements.txt
Copied!
Set Up Flask Environment
1
$ # CMD
2
$ set FLASK_APP=run.py
3
$ set FLASK_ENV=development
4
$
5
$ # Powershell
6
$ $env:FLASK_APP = ".\run.py"
7
$ $env:FLASK_ENV = "development"
Copied!
Start the app
1
$ flask run
Copied!
At this point, the app runs at http://127.0.0.1:5000/.

✨ Codebase structure

The project is coded using a simple and intuitive structure presented below:
1
< PROJECT ROOT >
2
|
3
|-- apps/
4
| |
5
| |-- static/
6
| | |-- <css, JS, images> # CSS files, Javascripts files
7
| |
8
| |-- templates/ # Templates used to render pages
9
| | |-- includes/ # HTML chunks and components
10
| | | |-- navigation.html # Top menu component
11
| | | |-- footer.html # App Footer
12
| | | |-- scripts.html # Scripts common to all pages
13
| | |
14
| | |-- layouts/ # Master pages
15
| | | |-- base-fullscreen.html # Used by Authentication pages
16
| | | |-- base.html # Used by common pages
17
| | |
18
| | |-- accounts/ # Authentication pages
19
| | | |-- login.html # Login page
20
| | | |-- register.html # Register page
21
| | |
22
| | |-- home/ # UI Kit Pages
23
| | |-- index.html # Index page
24
| | |-- page-404.html # 404 page
25
| | |-- *.html # All other pages
26
| |
27
| views.py # Implements app routing
28
| config.py # Set up the app
29
| __init__.py # Initialize the app
30
|
31
|-- requirements.txt # App Dependencies
32
|
33
|-- .env # Inject Configuration via Environment
34
|-- run.py # Start the app - WSGI gateway
35
|
36
|-- ************************************************************************
Copied!

✨ 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 masterpages
  • templates/includes: UI components (used across multiple pages)
  • templates/accounts: login & registration page
  • templates/home: all other pages served via a generic routing by apps/home app
1
< PROJECT ROOT >
2
|
3
|-- apps/
4
| |
5
| |-- static/
6
| | |-- <css, JS, images> # CSS files, Javascripts files
7
| |
8
| |-- templates/ # Templates used to render pages
9
| |-- includes/ # HTML chunks and components
10
| | |-- navigation.html # Top menu component
11
| | |-- footer.html # App Footer
12
| | |-- scripts.html # Scripts common to all pages
13
| |
14
| |-- layouts/ # Master pages
15
| | |-- base.html # Used by common pages
16
| |
17
| |-- accounts/ # Authentication pages
18
| | |-- login.html # Login page
19
| | |-- register.html # Register page
20
| |
21
| |-- home/ # UI Kit Pages
22
| |-- index.html # Index page
23
| |-- page-404.html # 404 page
24
| |-- *.html # All other pages
25
|
26
|-- ************************************************************************
Copied!

πŸ‘‰ 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
  • .env defines the ASSETS_ROOT variable
  • core/settings.py read the value of ASSETS_ROOT and defaults to /static/assets if not found:
1
# content of core/settings.py (truncated content)
2
​
3
ASSETS_ROOT = os.getenv('ASSETS_ROOT', '/static/assets')
Copied!
  • All pages and components use the config.ASSETS_ROOT variable. Here is a sample extracted from templates/layouts/base.html:
1
<head>
2
​
3
<!-- Source Code -->
4
<link rel="stylesheet" href="{{ config.ASSETS_ROOT }}/css/style.css">
5
​
6
<!-- RUNTIME -->
7
<link rel="stylesheet" href="/static/assets/css/style.css">
Copied!
At runtime, the href property is resolved to /static/assets/css/style.css based on the value saved in the .env file:
1
# No Slash at the end
2
ASSETS_ROOT=/static/assets
Copied!

πŸ‘‰ Static Assets for production

As explained in the Static Assets section, the assets are managed via:
  • apps/static/assets - the folder where JS, CSS, and images files are saved
  • ASSETS_ROOT - environment variable, that defaults to /static/assets if 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:
1
# No Slash at the end
2
ASSETS_ROOT=https://cdn.your-server.com/datta-able-assets
Copied!

πŸš€ Where to go from here

  • πŸ‘‰ Access the support page in case something is missing
  • πŸ‘‰ Use the App Generator to generate a new project