Introduction

django-rest-framework-datatables provides seamless integration between Django REST framework and Datatables.

Just call your API with ?format=datatables, and you will get a JSON structure that is fully compatible with what Datatables expects.

A “normal” call to your existing API will look like this:

$ curl http://127.0.0.1:8000/api/albums/ | python -m "json.tool"
{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "rank": 1,
            "name": "Sgt. Pepper's Lonely Hearts Club Band",
            "year": 1967,
            "artist_name": "The Beatles",
            "genres": "Psychedelic Rock, Rock & Roll"
        },
        {
            "rank": 2,
            "name": "Pet Sounds",
            "year": 1966,
            "artist_name": "The Beach Boys",
            "genres": "Pop Rock, Psychedelic Rock"
        }
    ]
}

The same call with datatables format will look a bit different:

$ curl http://127.0.0.1:8000/api/albums/?format=datatables | python -m "json.tool"
{
    "recordsFiltered": 2,
    "recordsTotal": 2,
    "draw": 1,
    "data": [
        {
            "rank": 1,
            "name": "Sgt. Pepper's Lonely Hearts Club Band",
            "year": 1967,
            "artist_name": "The Beatles",
            "genres": "Psychedelic Rock, Rock & Roll"
        },
        {
            "rank": 2,
            "name": "Pet Sounds",
            "year": 1966,
            "artist_name": "The Beach Boys",
            "genres": "Pop Rock, Psychedelic Rock"
        }
    ]
}

As you can see, django-rest-framework-datatables automatically adapt the JSON structure to what Datatables expects. And you don’t have to create a different API, your API will still work as usual unless you specify the datatables format on your request.

But django-rest-framework-datatables can do much more ! As you will learn in the tutorial, it speaks the Datatables language and can handle searching, filtering, ordering, pagination, etc. Read the quickstart guide for instructions on how to install and configure django-rest-framework-datatables.