Skip to main content

https://github.com/idlesign/django-siteajax

release lic coverage

Description

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.

Usage

Somewhere in your views.py:

from django.shortcuts import redirect, render
from siteajax.toolbox import ajax_dispatch


def 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:

<!DOCTYPE html>
<html>
<head>
    <!-- Get client library js from CDN. -->
    {% include "siteajax/cdn.html" %}
</head>
<body>
    <div id="news-list" hx-get hx-trigger="load"></div>
    <!-- The contents of the above div will be replaced
        with the news from your server automatically fetched on page load.
        Notice `hx-*` attributes driving htmx JS library.
        Also notice how `id="news-list"` is used by `@ajax_dispatch`
        view decorator (shown above). -->
</body>
</html>

At last sub_news.html (nothing special):

{% for item in news %}<div>{{ item.title }}</div>{% endfor %}

Documentation

https://django-siteajax.readthedocs.org/

Release files for django-siteajax 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-siteajax 1.0.0
File Size Uploaded
django-siteajax-1.0.0.tar.gz 16.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-siteajax 1.0.0
File Interpreter ABI Platform
django_siteajax-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.5 kB

Release files / django-siteajax-1.0.0.tar.gz

Download URL django-siteajax-1.0.0.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d221e635c8c0cfd8508f7657b25a30f479eeb3a3a33daf646584815799d13ac9
BLAKE2b-256 checksum
How to use checksums
6bc55c5592da441913e4b7d5cfa2042e96b907ebddb879dbb8308ef526c2e418
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

Release files / django_siteajax-1.0.0-py3-none-any.whl

Download URL django_siteajax-1.0.0-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
828d9f5680d274c818768c43f3f90908499942c866e3a3887b301739afbc573c
BLAKE2b-256 checksum
How to use checksums
c799297938a0cc60b1d24f1c75196d440ac923774824c42eab97dc7cd28155d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page