Serving flat pages with Django without views and database.
Helps to separate deployment of front- and backend.
django>= 2.0python>= 3.6
Install the latest release with pip:
pip install django-flatly
Than add a URL to urlpatterns:
# urls.py
urlpatterns = [
...,
# all others urls above - flatly.urls last one to try!
path('', include('flatly.urls')),
]-
In your root template directory create
flatlyfolder. -
Define
FLATLY_TEMPLATE_ROOTsetting:FLATLY_TEMPLATE_ROOT = 'flatly'
-
Any
.htmlfiles you create in yourflatlydirectory will be automatically served. So if you create a new fileflatly/about_us/overview.htmlthen it will be visible at/about-us/overview/.
Note that django-flatly automatically replaces underscores (_)
with dashes (-).
Suppose you are requesting the page /account/user-profile/,
django-flatly will render the first template that exists:
${FLATLY_TEMPLATE_ROOT}/account/user_profile${FLATLY_TEMPLATE_ROOT}/account/user_profile.html${FLATLY_TEMPLATE_ROOT}/account/user_profile/index.html
django-flatly based on Django's get_template function.
So, user can access any template on your website. You can
restrict access to certain templates by adding the path prefix
to the template name before search:
FLATLY_TEMPLATE_ROOT = 'flatly'Note that flatly folder can be located in both root and
application template directories.
Defaults to flatly.
You can restrict the template search to a particular template engine.
FLATLY_ENGINE = 'jinja2'Defaults to None.
By default (when DEBUG is True), the template system
searches, reads and compiles your templates every time
they’re rendered. It's convenient for local development,
because no need to restart the server after adding/removing
templates.
You can enforce template caching:
FLATLY_CACHE_ENABLED = TrueThe cached Template instance is returned for subsequent
requests to load the same template.
Defaults to True is settings.DEBUG is False.
List of file extensions to iterate over all matching files.
FLATLY_EXTENSIONS = ['html', 'jinja2']Defaults to ['html'].