All Projects → yceruto → Django Ajax

yceruto / Django Ajax

Licence: mit
Fast and easy AJAX libraries for django applications. Contains ajax decorator, ajax middleware, shortcuts and more.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Ajax

Muuntaja
Clojure library for fast http api format negotiation, encoding and decoding.
Stars: ✭ 304 (-2.56%)
Mutual labels:  middleware, json
Body Parser
Node.js body parsing middleware
Stars: ✭ 4,962 (+1490.38%)
Mutual labels:  middleware, json
Javascript ninja
javascript-ninja 😆
Stars: ✭ 11 (-96.47%)
Mutual labels:  json, ajax
Form
jQuery Form Plugin
Stars: ✭ 5,122 (+1541.67%)
Mutual labels:  json, ajax
Graphql Factory
A toolkit for building GraphQL
Stars: ✭ 44 (-85.9%)
Mutual labels:  middleware, json
Restclient
🦄 Simple HTTP and REST client for Unity based on Promises, also supports Callbacks! 🎮
Stars: ✭ 675 (+116.35%)
Mutual labels:  json, ajax
Wretch
A tiny wrapper built around fetch with an intuitive syntax. 🍬
Stars: ✭ 2,285 (+632.37%)
Mutual labels:  json, ajax
Ssm Bookappointment
优雅整合SSM框架:SpringMVC + Spring + MyBatis(用户登陆式图书预约系统)
Stars: ✭ 666 (+113.46%)
Mutual labels:  json, ajax
Wretch Middlewares
Collection of middlewares for the Wretch library. 🎁
Stars: ✭ 42 (-86.54%)
Mutual labels:  middleware, ajax
Redux Json Router
Declarative, Redux-first routing for React/Redux browser applications.
Stars: ✭ 37 (-88.14%)
Mutual labels:  middleware, json
Tabulator
Interactive Tables and Data Grids for JavaScript
Stars: ✭ 4,329 (+1287.5%)
Mutual labels:  json, ajax
Goat
[DEPRECATED] 🐐 A minimalistic JSON API server in Go
Stars: ✭ 161 (-48.4%)
Mutual labels:  middleware, json
Fetch Plus
🐕 Fetch+ is a convenient Fetch API replacement with first-class middleware support.
Stars: ✭ 116 (-62.82%)
Mutual labels:  json, ajax
Apicache
Simple API-caching middleware for Express/Node.
Stars: ✭ 957 (+206.73%)
Mutual labels:  middleware, json
Tesla
The flexible HTTP client library for Elixir, with support for middleware and multiple adapters.
Stars: ✭ 1,588 (+408.97%)
Mutual labels:  middleware, json
Ring Json
Ring middleware for handling JSON
Stars: ✭ 290 (-7.05%)
Mutual labels:  middleware, json
Loading Bar
Flexible, light weighted and super fast Progress Bar Library
Stars: ✭ 300 (-3.85%)
Mutual labels:  ajax
Bebop
An extremely simple, fast, efficient, cross-platform serialization format
Stars: ✭ 305 (-2.24%)
Mutual labels:  json
Fspickler
A fast multi-format message serializer for .NET
Stars: ✭ 299 (-4.17%)
Mutual labels:  json
Fractalistic
A framework agnostic, developer friendly wrapper around Fractal
Stars: ✭ 309 (-0.96%)
Mutual labels:  json

=========== django-ajax

Fast and easy AJAX libraries for django applications.

.. image:: https://travis-ci.org/yceruto/django-ajax.svg?branch=master :alt: Master Build Status :target: https://travis-ci.org/yceruto/django-ajax

.. image:: https://img.shields.io/pypi/v/djangoajax.svg :alt: PYPI Package :target: https://pypi.python.org/pypi/djangoajax

.. image:: https://img.shields.io/pypi/status/django-ajax.svg :alt: PYPI Status :target: https://pypi.python.org/pypi/djangoajax

.. image:: https://img.shields.io/pypi/l/djangoajax.svg :alt: PYPI License :target: https://pypi.python.org/pypi/djangoajax

Requirements

3.x

  • python_ >=3.5
  • django_ >=2.0

2.x

  • python_ >=2.7
  • django_ >=1.7,<2.0

.. _python: http://www.python.org/ .. _django: https://djangoproject.com .. _jQuery: http://jquery.com

Installation

Install django-ajax in your python environment

1- Download and install package:

.. code:: sh

$ pip install djangoajax

Through Github:

.. code:: sh

pip install -e git://github.com/yceruto/django-ajax#egg=djangoajax

or simply with:

.. code:: sh

$ python setup.py install

2- Add 'django_ajax' into the INSTALLED_APPS list.

3- Read usage section and enjoy this feature!

Usage

@ajax Decorator


.. code:: python

    from django_ajax.decorators import ajax

    @ajax
    def my_view(request):
        do_something()
        
When the view does not return anything, you will receive this response (JSON format):

.. code:: javascript

    {"status": 200, "statusText": "OK", "content ": null}


**Sending content**

.. code:: python

    @ajax
    def my_view(request):
        c = 2 + 3
        return {'result': c}
        
The whole result is converted into a JSON format as part of the `content` element:

.. code:: javascript

    {"status": 200, "statusText": "OK", "content": {"result": 5}}


**Combining with others decorators**

.. code:: python

    from django.contrib.auth.decorators import login_required
    from django_ajax.decorators import ajax

    @ajax
    @login_required
    def my_view(request):
        # if the request.user is anonymous then this view not proceed 
        return {'user_id': request.user.id}
        
The location or path of the redirection response will be given in the `content` item, 
also the `status` and `statusText` will reflect what is going on:

.. code:: javascript

    {"status": 302, "statusText": "FOUND", "content": "/login"}


**Template response**

.. code:: python

    from django.shortcuts import render
    from django_ajax.decorators import ajax

    @ajax
    def my_view(request):
        return render(request, 'home.html')

The JSON response:

.. code:: javascript

    {"status": 200, "statusText": "OK", "content": "<html>...</html>"}


**Catch exceptions**

.. code:: python

    @ajax
    def my_view(request):
        a = 23 / 0  # this line throws an exception
        return a

The JSON response:

.. code:: javascript

    {"status": 500, "statusText": "INTERNAL SERVER ERROR", "content": "integer division or modulo by zero"}


AJAXMiddleware
~~~~~~~~~~~~~~

If you are using AJAX at all times in your project, we suggest you activate the AJAXMiddleware described below.

Add ``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.

.. caution:: If this middleware is activated you cannot use the ``@ajax`` decorator. That will cause double JSON conversion.


AJAXMixin for class-based views

AJAXMixin is an object that call to AJAX decorator.

.. code:: python

from django.views.generic import TemplateView
from django_ajax.mixin import AJAXMixin

class SimpleView(AJAXMixin, TemplateView):
    template_name = 'home.html'

The JSON response:

.. code:: javascript

{"status": 200, "statusText": "OK", "content": "<html>...</html>"}

Enjoy And Share!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].