Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/idlesign/django-siteajax
Reusable application for Django bridging client and server sides
https://github.com/idlesign/django-siteajax
ajax django-application htmx htmx-django xhr
Last synced: 26 days ago
JSON representation
Reusable application for Django bridging client and server sides
- Host: GitHub
- URL: https://github.com/idlesign/django-siteajax
- Owner: idlesign
- License: bsd-3-clause
- Created: 2021-05-25T10:57:04.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-21T03:08:52.000Z (almost 2 years ago)
- Last Synced: 2024-10-01T18:08:13.436Z (about 1 month ago)
- Topics: ajax, django-application, htmx, htmx-django, xhr
- Language: Python
- Homepage:
- Size: 70.3 KB
- Stars: 31
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG
- Contributing: CONTRIBUTING
- License: LICENSE
Awesome Lists containing this project
- awesome-python-htmx - django-siteajax - Django-a9bbcc?style=flat&logo=django&logoColor=black" alt="Django"></a> <br/> (Third Party Packages 📦 <a name = "tools"></a> / Helper Libraries)
README
django-siteajax
===============
https://github.com/idlesign/django-siteajax|release| |lic| |coverage|
.. |release| image:: https://img.shields.io/pypi/v/django-siteajax.svg
:target: https://pypi.python.org/pypi/django-siteajax.. |lic| image:: https://img.shields.io/pypi/l/django-siteajax.svg
:target: https://pypi.python.org/pypi/django-siteajax.. |coverage| image:: https://img.shields.io/coveralls/idlesign/django-siteajax/master.svg
:target: https://coveralls.io/r/idlesign/django-siteajaxDescription
-----------*Reusable application for Django bridging client and server sides*
Streamline your server and client interaction using declarative techniques
in your HTML and helpful abstractions from ``siteajax`` in your Python code... note:: The client side of ``siteajax`` is powered by ``htmx``
(the successor of ``intercooler.js``) - https://htmx.org/Usage
-----Somewhere in your ``views.py``:
.. code-block:: python
from django.shortcuts import redirect, render
from siteajax.toolbox import ajax_dispatchdef get_news(request):
news = ... # Here we fetch some news from DB.
# We could access `request.ajax` object properties
# or even drive client side with the help
# of siteajax.toolbox.AjaxResponse but for this demo
# simple rendering is enough.
return render(request, 'sub_news.html', {'news': news})@ajax_dispatch({
# Map request source element id (see html below)
# to a handler.
'news-list': get_news,
})
def index_page(request):
"""Suppose this view is served at /"""
return render(request, 'index.html')Now to your ``index.html``:
.. code-block:: html
{% include "siteajax/cdn.html" %}
At last ``sub_news.html`` (nothing special):
.. code-block:: html
{% for item in news %}
{{ item.title }}{% endfor %}Documentation
-------------https://django-siteajax.readthedocs.org/