djk_ui

django-jinja-knockout supports Bootstrap 3 / Bootstrap 4 / Bootstrap 5 via the djk_ui Django application module.

djk_ui module is installed from djk-bootstrap3 / djk-bootstrap4 / djk-bootstrap5 packages, respectively. This means that djk-bootstrap3 / djk-bootstrap4 / djk-bootstrap5 packages are mutually exclusive and only one has to be installed in the project virtualenv at the same time.

Unfortunately pip does not support requirements.txt files with de-installation directives. Thus one has to use pip with separate requirements-bs3.txt / requirements-bs4.txt / requirements-bs5.txt files, to install the current stable version, or to copy and then run 3bs.sh / 4bs.sh / 5bs.sh shell scripts, to switch between current master (possibly unstable) versions of djk_ui. Usually most of projects does not require changing Bootstrap version on the fly, so that’s not much of problem.

conf.py

Contains the default layout_classes values, for example for Bootstrap 5 (version 2.2.0):

LAYOUT_CLASSES = {
    '': {
        'label': 'col-md-3',
        'field': 'col-md-7',
    },
    'display': {
        'label': 'w-25 table-info',
        'field': 'w-100 table-light',
    },
}

where ‘’ key specifies the layout classes of editable model forms, ‘display’ key specifies the layout classes of the display-only model forms.

These default values can be overridden via the project settings module LAYOUT_CLASSES variable. See also opts argument for more info how layout classes are applied to form / formset renderers; see Changing bootstrap grid layout how layout classes are used in form / formset macros.

tpl.py

Contains nested list / dict formatters, specific to used Bootstrap version. See tpl.py for more info.

Customization

This module implements both server-side (Python) and client-side (Javascript) parts of the code that differs between Bootstrap 3 / Bootstrap 4 / Bootstrap 5. While it’s possible to implement much larger djk_ui wrappers for more generic non-Bootstrap based UIs, currently I do not have enough of time / resources for that.