Serving flat pages with Django without views and database.
Project description
django-flatly
Serving flat pages with Django without views and database.
Helps to separate deployment of front- and backend.
Installation
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')),
]
Quick start
-
In your root template directory create
flatly
folder. -
Define
FLATLY_TEMPLATE_ROOT
setting:FLATLY_TEMPLATE_ROOT = 'flatly'
-
Any
.html
files you create in yourflatly
directory will be automatically served. So if you create a new fileflatly/about_us/overview.html
then it will be visible at/about-us/overview/
.
Note that django-flatly
automatically replaces underscores (_)
with dashes (-).
Search path
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
Settings
Template root
django-flatly
based on Django's get_template
function.
So, any user can access any template on your website. You can
restrict access to certain templates by adding the following:
FLATLY_TEMPLATE_ROOT = 'flatly'
By adding the above configuration django-flatly
will add
specified path prefix to the template name before search.
Suppose you are requesting the page /account/user/
,
django-flatly
will call something like
get_template('flatly/account/user.html')
.
Note that flatly
folder can be located in both root and
application template directories.
Defaults to None
.
Template engine
You can restrict the template search to a particular template engine.
FLATLY_ENGINE = 'jinja2'
Defaults to None
.
Extensions
List of file extensions to iterate over all matching files.
FLATLY_EXTENSIONS = ['html', 'jinja2']
Defaults to html
.
Development and Testing
After cloning the Git repository, you should install this in a virtualenv and set up for development:
virtualenv .venv
source .venv/bin/activate
pip install -e .[dev]
Then, you can run tests:
pytest
# or
tox -e py38-django30
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_flatly-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8026dcc0005f7c3d69ba485daa574cc72eebc283c5866ac028c93bef8cab5ad1 |
|
MD5 | 928c350b3a77fe469515178e9d8014c2 |
|
BLAKE2b-256 | 2b1257727b386cf9e5f9919a981eb6edc4068c7975d0a4720bb6ddd6e97d4019 |