django-jinja-knockout

Django datatables and widgets, both AJAX and traditional. Display-only ModelForms. ModelForms / inline formsets with AJAX submit and validation. Works with Django templates.

OTHER License

Downloads
637
Stars
144
Committers
9

=====================
django-jinja-knockout

.. _aggregate: https://docs.djangoproject.com/en/dev/topics/db/aggregation/#generating-aggregates-over-a-queryset .. _axios: https://axios-http.com/docs/intro .. _Compound columns: https://django-jinja-knockout.readthedocs.io/en/latest/datatables.html#compound-columns .. _custom elements: https://github.com/Dmitri-Sintsov/django-jinja-knockout/blob/master/django_jinja_knockout/static/djk/js/elements.js .. _renderValue: https://github.com/Dmitri-Sintsov/django-jinja-knockout/search?q=renderValue&unscoped_q=renderValue .. _renderNestedList: https://django-jinja-knockout.readthedocs.io/en/latest/datatables.html#nested-verbose-field-names .. _button_pagination: https://github.com/Dmitri-Sintsov/django-jinja-knockout/search?q=button_pagination&type=code .. _Bootstrap 3: https://github.com/Dmitri-Sintsov/djk-bootstrap3 .. _Bootstrap 4: https://github.com/Dmitri-Sintsov/djk-bootstrap4 .. _Bootstrap 5: https://github.com/Dmitri-Sintsov/djk-bootstrap5 .. _Bootstrap Icons: https://icons.getbootstrap.com/ .. _data-bind: https://knockoutjs.com/documentation/binding-syntax.html .. _datatables: https://django-jinja-knockout.readthedocs.io/en/latest/datatables.html .. _django_deno: https://github.com/Dmitri-Sintsov/django-deno .. _django-jinja-knockout python localization: https://poeditor.com/join/project/9hqQrFEdDM .. _django-jinja-knockout javascript localization: https://poeditor.com/join/project/049HWzP3eb .. _djk_bootstrap5: https://github.com/Dmitri-Sintsov/djk-bootstrap5 .. _empty_form: https://docs.djangoproject.com/en/dev/topics/forms/formsets/#empty-form .. _es6 modules: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules .. _fields_template: https://github.com/Dmitri-Sintsov/django-jinja-knockout/search?q=fields_template .. _FilteredRawQuerySet: https://django-jinja-knockout.readthedocs.io/en/latest/query.html#filteredrawqueryset .. _ForeignKeyGridWidget: https://django-jinja-knockout.readthedocs.io/en/latest/widgets.html#foreignkeygridwidget .. _ForeignKeyRawIdWidget: https://github.com/django/django/search?l=Python&q=ForeignKeyRawIdWidget .. _FormFieldsRenderer: https://github.com/Dmitri-Sintsov/django-jinja-knockout/search?q=FormFieldsRenderer .. _get_absolute_url: https://github.com/Dmitri-Sintsov/django-jinja-knockout/search?l=Python&q=get_absolute_url .. _iconui: https://django-jinja-knockout.readthedocs.io/en/latest/datatables.html#action-type-iconui .. _Jinja2: http://jinja.pocoo.org/docs/dev/ .. _kiwnix: https://github.com/Dmitri-Sintsov/django-jinja-knockout/commits?author=kiwnix .. _Knockout.js: http://knockoutjs.com/ .. _ko_grid_navs_filter_choices: https://github.com/Dmitri-Sintsov/django-jinja-knockout/search?q=ko_grid_navs_filter_choices&type=code .. _ListView: https://docs.djangoproject.com/en/dev/ref/class-based-views/generic-display/#listview .. _ListRangeFilter: https://github.com/Dmitri-Sintsov/django-jinja-knockout/search?q=ListRangeFilter&type=code .. _ListSortingView: https://django-jinja-knockout.readthedocs.io/en/latest/views.html#listsortingview .. _KoGridView: https://django-jinja-knockout.readthedocs.io/en/latest/datatables.html .. _ListQuerySet: https://django-jinja-knockout.readthedocs.io/en/latest/query.html#listqueryset .. _many to many relationships: https://docs.djangoproject.com/en/dev/topics/db/examples/many_to_many/ .. _ModelForm: https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#modelform .. _MultipleKeyGridWidget: https://django-jinja-knockout.readthedocs.io/en/latest/datatables.html#multiplekeygridwidget .. _Nested components: https://django-jinja-knockout.readthedocs.io/en/latest/clientside.html#clientside-nested-components .. _ObjDict: https://github.com/Dmitri-Sintsov/django-jinja-knockout/search?l=Python&q=objdict .. _PageContext: https://django-jinja-knockout.readthedocs.io/en/latest/context_processors.html#pagecontext-page-context .. _pageRouteKwargsKeys: https://github.com/Dmitri-Sintsov/django-jinja-knockout/search?l=Python&q=pageRouteKwargsKeys&type=code .. _pageRouteKwargsKeys example: https://github.com/Dmitri-Sintsov/djk-sample/search?q=pageRouteKwargsKeys&type=code .. _prefetch_related(): https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.Prefetch .. _sample project: https://github.com/Dmitri-Sintsov/djk-sample .. _SystemJS: https://github.com/systemjs/systemjs .. _TemplateResponse: https://docs.djangoproject.com/en/dev/ref/template-response/ .. _terser: https://terser.org .. _Tpl.domTemplate: https://github.com/Dmitri-Sintsov/django-jinja-knockout/search?q=domTemplate&type=code .. _UrlPath: https://github.com/Dmitri-Sintsov/djk-sample/search?l=Python&q=UrlPath .. _UrlSearchParams: https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams .. _viewmodels: https://django-jinja-knockout.readthedocs.io/en/latest/viewmodels.html

.. image:: https://badge.fury.io/py/django-jinja-knockout.png :alt: PyPI package :target: https://badge.fury.io/py/django-jinja-knockout

.. image:: https://readthedocs.org/projects/django-jinja-knockout/badge/?version=latest :alt: Documentation Status :target: https://django-jinja-knockout.readthedocs.io/en/latest/?badge=latest

.. image:: https://icons.iconarchive.com/icons/dtafalonso/android-lollipop/24/Youtube-icon.png :alt: Watch selenium tests recorded videos. :target: https://www.youtube.com/channel/UCZTrByxVSXdyW0z3e3qjTsQ

.. image:: https://badges.gitter.im/django-jinja-knockout/Lobby.svg :alt: Join the chat at https://gitter.im/django-jinja-knockout/Lobby :target: https://gitter.im/django-jinja-knockout/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge

Screenshot of the sample project_:

.. image:: https://raw.githubusercontent.com/wiki/Dmitri-Sintsov/djk-sample/djk_edit_inline.png :width: 740px

More screenshots with descriptions are available at: https://github.com/Dmitri-Sintsov/djk-sample/wiki

Documentation (in development): https://django-jinja-knockout.readthedocs.org/

  • Supports Django 4.2 LTS, 5.1; Python 3.10 / 3.11 / 3.12.

Please contribute to the localization of the project:

  • django-jinja-knockout python localization_
  • django-jinja-knockout javascript localization_

Localization:

  • Chinese: goldmonkey
  • Dutch: Melvyn Sopacua
  • Polish: pawelkoston
  • Spanish: Julio Cesar Cabrera Cabrera, kiwnix_

Key features

  • AJAX based django.admin-like paginated datatables_ (grids) with sorting / filters and custom actions.

  • Integrates Jinja2 into existing Django templates (DTL).

  • Bootstrap 3_ / Bootstrap 4_ / Bootstrap 5_ / Jinja2_ / Knockout.js_ for Django projects.

  • No deep knowledge of Knockout.js is required: it has ready working components.

  • Dynamic adding / removing of inline formsets with Knockout.js, protected from XSS.

  • Default template renderers for Django forms / related forms / inline formsets with the possibility to override these to customize the visual layout.

  • ForeignKeyGridWidget_ provides ForeignKeyRawIdWidget-like functionality to select ModelForm foreign key field value via AJAX query / response.

  • Django raw queries with filter() / exclude() / order() / values() / values_list() and SQL slicing support via FilteredRawQuerySet, suitable for usage in ListView / ListSortingView_ / KoGridView_ derived classes.

  • ListQuerySet_ to query Python lists, including prefetch_related()_ results.

  • Jinja2 templates can be integrated into existing Django templates via custom template library tag::

    {% extends 'base_min.html' %} {% load jinja %} {% load static %}

    {% block main %} {% jinja 'bs_list.htm' with render=1 view=view object_list=object_list is_paginated=is_paginated page_obj=page_obj %} {% endblock main %}

Overview

Knockout.js uses unobtrusive data-bind_ HTML attributes with JSON-like values with causes no conflict to server-side double braces template syntax of DTL / Jinja2: no need to escape templates.

Combining client-side Knockout.js templates and server-side Jinja2 templates allows to write more powerful and compact template code.

Jinja2 is faster and is more powerful than built-in DTL templates. Jinja2 templates may be called from DTL templates by using custom template tag library {% load jinja %}.

Uses

It's not a pure SPA framework, but a mixed approach of server-side pages with embedded AJAX content and client-side scripts. Although it may be used for SPA as well. Classical Web applications aren't "outdated" in any way - because such applications are much better indexable by web crawlers, Python is better language than Javascript in general, also server-side rendering generally is more robust.

Version 2.2.1

Python 3.12 / Django 5.1 compatibility.

Use axios_ instead of outdated jQuery.form plugin.

Version 2.2.0

FormFieldsRenderer_ / fields_template_ allows fine-grained customization of ModelForm_ fields layout.

ListQuerySet_ now has basic support of .delete() method and most common aggregate_ functions: Count, Min, Max, Sum.

Load jQuery.form / Moment.js / Bootstrap Datetimepicker as es6 modules, which may be included into django_deno generated bundle.

QueryString wrapper for UrlSearchParams_.

Additional KoGridView_ client-side layout options:

  • Bootstrap navs style of Grid filter choices: ko_grid_navs_filter_choices_
  • showNonSortableColumnNames option
  • button_pagination_ built-in action type

Nested components_ are supported in Grid cells, including the cells of Compound columns_.

Tpl.domTemplate_ optional template kwargs support.

djk_bootstrap5_ now uses native Bootstrap Icons_ font for iconui_ actions.

Various bugfixes.

Version 2.1.0

Built-in custom elements_, including es5 IE11 polyfills.

Bootstrap 5_ compatibility.

ObjDict_ Django model serializer with built-in field permissions check for AJAX viewmodels, including datatables.

get_absolute_url_ with optional user permission check / link title generation.

Version 2.0.0

Built-in es6 modules_ support for modern browsers.

Optional SystemJS_ loader support for IE11 via django_deno_.

Optional minified terser_ bundles support both for es6 modules_ and for SystemJS_ loader via django_deno_.

datatables_ support separate cell click actions, not just row actions.

More throughout support for datatables_ annotated fields / virtual fields via grid_fields dicts.

Optional lazy registration of client-side components.

Numerous fixes, including improved related grid view kwargs auto-detection, see pageRouteKwargsKeys_ and pageRouteKwargsKeys example_.

ListRangeFilter_ for ListSortingView_ range fields.

.. _History: HISTORY.rst

.. _Changes: CHANGES.rst

Documentation

The full documentation is at https://django-jinja-knockout.readthedocs.org.

.. github relative links .. see setup.py

Quick notes

.. Next links are github relative links. Do not process these via sphinx as it does not follow them correctly. .. _Credits: AUTHORS.rst .. _contribute: CONTRIBUTING.rst .. _Changes: CHANGES.rst .. _History: HISTORY.rst .. _Installation: INSTALLATION.rst .. _Introduction: QUICKSTART.rst

  • Installation_
  • Introduction_
  • How to contribute_
  • History_
  • Changes_
  • Credits_

Cookiecutter Tools Used in Making This Package

  • cookiecutter
  • cookiecutter-djangopackage