django-siteajax


Namedjango-siteajax JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/idlesign/django-siteajax
SummaryReusable application for Django bridging client and server sides
upload_time2023-01-21 03:54:59
maintainer
docs_urlNone
authorIgor `idle sign` Starikov
requires_python
licenseBSD 3-Clause License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            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-siteajax


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.

.. 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_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``:

.. code-block:: 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):

.. code-block:: html

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


Documentation
-------------

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



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/idlesign/django-siteajax",
    "name": "django-siteajax",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Igor `idle sign` Starikov",
    "author_email": "idlesign@yandex.ru",
    "download_url": "https://files.pythonhosted.org/packages/6b/c5/5c5592da441913e4b7d5cfa2042e96b907ebddb879dbb8308ef526c2e418/django-siteajax-1.0.0.tar.gz",
    "platform": null,
    "description": "django-siteajax\n===============\nhttps://github.com/idlesign/django-siteajax\n\n|release| |lic| |coverage|\n\n.. |release| image:: https://img.shields.io/pypi/v/django-siteajax.svg\n    :target: https://pypi.python.org/pypi/django-siteajax\n\n.. |lic| image:: https://img.shields.io/pypi/l/django-siteajax.svg\n    :target: https://pypi.python.org/pypi/django-siteajax\n\n.. |coverage| image:: https://img.shields.io/coveralls/idlesign/django-siteajax/master.svg\n    :target: https://coveralls.io/r/idlesign/django-siteajax\n\n\nDescription\n-----------\n\n*Reusable application for Django bridging client and server sides*\n\nStreamline your server and client interaction using declarative techniques\nin your HTML and helpful abstractions from ``siteajax`` in your Python code.\n\n.. note:: The client side of ``siteajax`` is powered by ``htmx``\n  (the successor of ``intercooler.js``) - https://htmx.org/\n\nUsage\n-----\n\nSomewhere in your ``views.py``:\n\n.. code-block:: python\n\n    from django.shortcuts import redirect, render\n    from siteajax.toolbox import ajax_dispatch\n\n\n    def get_news(request):\n        news = ...  # Here we fetch some news from DB.\n        # We could access `request.ajax` object properties\n        # or even drive client side with the help\n        # of siteajax.toolbox.AjaxResponse but for this demo\n        # simple rendering is enough.\n        return render(request, 'sub_news.html', {'news': news})\n\n    @ajax_dispatch({\n        # Map request source element id (see html below)\n        # to a handler.\n        'news-list': get_news,\n    })\n    def index_page(request):\n        \"\"\"Suppose this view is served at /\"\"\"\n        return render(request, 'index.html')\n\n\nNow to your ``index.html``:\n\n.. code-block:: html\n\n    <!DOCTYPE html>\n    <html>\n    <head>\n        <!-- Get client library js from CDN. -->\n        {% include \"siteajax/cdn.html\" %}\n    </head>\n    <body>\n        <div id=\"news-list\" hx-get hx-trigger=\"load\"></div>\n        <!-- The contents of the above div will be replaced\n            with the news from your server automatically fetched on page load.\n            Notice `hx-*` attributes driving htmx JS library.\n            Also notice how `id=\"news-list\"` is used by `@ajax_dispatch`\n            view decorator (shown above). -->\n    </body>\n    </html>\n\n\nAt last ``sub_news.html`` (nothing special):\n\n.. code-block:: html\n\n    {% for item in news %}<div>{{ item.title }}</div>{% endfor %}\n\n\nDocumentation\n-------------\n\nhttps://django-siteajax.readthedocs.org/\n\n\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License",
    "summary": "Reusable application for Django bridging client and server sides",
    "version": "1.0.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c799297938a0cc60b1d24f1c75196d440ac923774824c42eab97dc7cd28155d8",
                "md5": "0f290a4a4fc8f91ba11244c5b34dedf2",
                "sha256": "828d9f5680d274c818768c43f3f90908499942c866e3a3887b301739afbc573c"
            },
            "downloads": -1,
            "filename": "django_siteajax-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0f290a4a4fc8f91ba11244c5b34dedf2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 13500,
            "upload_time": "2023-01-21T03:54:57",
            "upload_time_iso_8601": "2023-01-21T03:54:57.237110Z",
            "url": "https://files.pythonhosted.org/packages/c7/99/297938a0cc60b1d24f1c75196d440ac923774824c42eab97dc7cd28155d8/django_siteajax-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6bc55c5592da441913e4b7d5cfa2042e96b907ebddb879dbb8308ef526c2e418",
                "md5": "32f4a999e99c2a93d34c2da18fe9c6ba",
                "sha256": "d221e635c8c0cfd8508f7657b25a30f479eeb3a3a33daf646584815799d13ac9"
            },
            "downloads": -1,
            "filename": "django-siteajax-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "32f4a999e99c2a93d34c2da18fe9c6ba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 16024,
            "upload_time": "2023-01-21T03:54:59",
            "upload_time_iso_8601": "2023-01-21T03:54:59.576301Z",
            "url": "https://files.pythonhosted.org/packages/6b/c5/5c5592da441913e4b7d5cfa2042e96b907ebddb879dbb8308ef526c2e418/django-siteajax-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-21 03:54:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "idlesign",
    "github_project": "django-siteajax",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "django-siteajax"
}
        
Elapsed time: 0.02984s