{"id":13411500,"url":"https://github.com/yceruto/django-ajax","last_synced_at":"2025-04-12T11:49:45.856Z","repository":{"id":9534317,"uuid":"11436765","full_name":"yceruto/django-ajax","owner":"yceruto","description":"Fast and easy AJAX libraries for django applications. Contains ajax decorator, ajax middleware, shortcuts and more.","archived":false,"fork":false,"pushed_at":"2024-04-27T20:52:14.000Z","size":248,"stargazers_count":323,"open_issues_count":0,"forks_count":57,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-04-03T11:09:30.246Z","etag":null,"topics":["ajax","django-framework","json","middleware","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yceruto.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["yceruto"]}},"created_at":"2013-07-16T00:16:20.000Z","updated_at":"2025-03-02T17:09:04.000Z","dependencies_parsed_at":"2024-06-18T16:53:09.594Z","dependency_job_id":"8edf5358-f357-4546-b656-e86761746617","html_url":"https://github.com/yceruto/django-ajax","commit_stats":{"total_commits":374,"total_committers":13,"mean_commits":28.76923076923077,"dds":0.5641711229946524,"last_synced_commit":"66d749829d25af58f60fb09f384f6f63053f6692"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yceruto%2Fdjango-ajax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yceruto%2Fdjango-ajax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yceruto%2Fdjango-ajax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yceruto%2Fdjango-ajax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yceruto","download_url":"https://codeload.github.com/yceruto/django-ajax/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248564889,"owners_count":21125412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ajax","django-framework","json","middleware","python"],"created_at":"2024-07-30T20:01:14.097Z","updated_at":"2025-04-12T11:49:45.834Z","avatar_url":"https://github.com/yceruto.png","language":"Python","funding_links":["https://github.com/sponsors/yceruto"],"categories":["Python","Web Development"],"sub_categories":["Python"],"readme":"===========\ndjango-ajax\n===========\n\nFast and easy AJAX libraries for django applications.\n\n.. image:: https://api.travis-ci.com/yceruto/django-ajax.svg?branch=master\n    :alt: Master Build Status\n    :target: https://travis-ci.com/github/yceruto/django-ajax\n    \n.. image:: https://img.shields.io/pypi/v/djangoajax.svg\n    :alt: PYPI Package\n    :target: https://pypi.python.org/pypi/djangoajax\n    \n.. image:: https://img.shields.io/pypi/status/django-ajax.svg\n    :alt: PYPI Status\n    :target: https://pypi.python.org/pypi/djangoajax\n    \n.. image:: https://img.shields.io/pypi/l/djangoajax.svg\n    :alt: PYPI License\n    :target: https://pypi.python.org/pypi/djangoajax\n\nRequirements\n------------\n\n``3.x``\n\n* `python`_ \u003e=3.5\n* `django`_ \u003e=2.0\n\n``2.x``\n\n* `python`_ \u003e=2.7\n* `django`_ \u003e=1.7,\u003c2.0\n\n.. _`python`: http://www.python.org/\n.. _`django`: https://djangoproject.com\n.. _`jQuery`: http://jquery.com\n\nInstallation\n------------\n\nInstall django-ajax in your python environment\n\n1- Download and install package:\n\n.. code:: sh\n\n    $ pip install djangoajax\n\nThrough Github:\n\n.. code:: sh\n\n    pip install -e git://github.com/yceruto/django-ajax#egg=djangoajax\n\nor simply with:\n\n.. code:: sh\n\n    $ python setup.py install\n\n2- Add ``'django_ajax'`` into the ``INSTALLED_APPS`` list.\n\n3- Read usage section and enjoy this feature!\n\n\nUsage\n-----\n\n@ajax Decorator\n~~~~~~~~~~~~~~~\n\n.. code:: python\n\n    from django_ajax.decorators import ajax\n\n    @ajax\n    def my_view(request):\n        do_something()\n        \nWhen the view does not return anything, you will receive this response (JSON format):\n\n.. code:: javascript\n\n    {\"status\": 200, \"statusText\": \"OK\", \"content \": null}\n\n\n**Sending content**\n\n.. code:: python\n\n    @ajax\n    def my_view(request):\n        c = 2 + 3\n        return {'result': c}\n        \nThe whole result is converted into a JSON format as part of the `content` element:\n\n.. code:: javascript\n\n    {\"status\": 200, \"statusText\": \"OK\", \"content\": {\"result\": 5}}\n\n\n**Combining with others decorators**\n\n.. code:: python\n\n    from django.contrib.auth.decorators import login_required\n    from django_ajax.decorators import ajax\n\n    @ajax\n    @login_required\n    def my_view(request):\n        # if the request.user is anonymous then this view not proceed \n        return {'user_id': request.user.id}\n        \nThe location or path of the redirection response will be given in the `content` item, \nalso the `status` and `statusText` will reflect what is going on:\n\n.. code:: javascript\n\n    {\"status\": 302, \"statusText\": \"FOUND\", \"content\": \"/login\"}\n\n\n**Template response**\n\n.. code:: python\n\n    from django.shortcuts import render\n    from django_ajax.decorators import ajax\n\n    @ajax\n    def my_view(request):\n        return render(request, 'home.html')\n\nThe JSON response:\n\n.. code:: javascript\n\n    {\"status\": 200, \"statusText\": \"OK\", \"content\": \"\u003chtml\u003e...\u003c/html\u003e\"}\n\n\n**Catch exceptions**\n\n.. code:: python\n\n    @ajax\n    def my_view(request):\n        a = 23 / 0  # this line throws an exception\n        return a\n\nThe JSON response:\n\n.. code:: javascript\n\n    {\"status\": 500, \"statusText\": \"INTERNAL SERVER ERROR\", \"content\": \"integer division or modulo by zero\"}\n\n\nAJAXMiddleware\n~~~~~~~~~~~~~~\n\nIf you are using AJAX at all times in your project, we suggest you activate the AJAXMiddleware described below.\n\nAdd ``django_ajax.middleware.AJAXMiddleware`` to the ``MIDDLEWARE_CLASSES`` list in ``settings.py`` and all your responses will be converted to JSON whereas the request was made via AJAX, otherwise it will return a normal HttpResponse.\n\n.. caution:: If this middleware is activated you cannot use the ``@ajax`` decorator. That will cause double JSON conversion.\n\n\nAJAXMixin for class-based views\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n``AJAXMixin`` is an object that call to AJAX decorator.\n\n.. code:: python\n\n    from django.views.generic import TemplateView\n    from django_ajax.mixin import AJAXMixin\n\n    class SimpleView(AJAXMixin, TemplateView):\n        template_name = 'home.html'\n\nThe JSON response:\n\n.. code:: javascript\n\n    {\"status\": 200, \"statusText\": \"OK\", \"content\": \"\u003chtml\u003e...\u003c/html\u003e\"}\n\nEnjoy And Share!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyceruto%2Fdjango-ajax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyceruto%2Fdjango-ajax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyceruto%2Fdjango-ajax/lists"}