dj-datatables-view

raw JSON →
0.1.8 verified Mon Apr 27 auth: no python

A Django library that provides a view for rendering DataTables with server-side processing. Fork of django-datatables-view. Current version 0.1.8, release cadence is low. Requires Python >=3.5,<4.0.

pip install dj-datatables-view
error ImportError: No module named 'dj_datatables_view'
cause Incorrect import path; the module is 'dj_datatables', not 'dj_datatables_view'.
fix
Use 'from dj_datatables.views import DatatableView'
error AttributeError: 'DatatableView' object has no attribute 'columns'
cause Columns attribute missing or not defined in the view class.
fix
Add 'columns = [...]' to your view class, e.g., columns = ['name', 'age']
error TypeError: __init__() got an unexpected keyword argument 'ordering'
cause Passing unsupported arguments to the view or model manager.
fix
Check that you are not overriding __init__ incorrectly; use standard queryset configuration.
gotcha Do not confuse with 'django-datatables-view' (original). Import path is 'dj_datatables', not 'dj_datatables_view'.
fix Use 'from dj_datatables.views import DatatableView'
gotcha The 'columns' attribute must match DataTables column definitions exactly, including ordering and names.
fix Define columns as list of strings in the same order as your DataTable JS column definitions.
deprecated Python 3.5-3.9 support is likely dropped in practice; library requires Python >=3.5 but unmaintained since 2021.
fix Consider migrating to modern alternatives like 'django-datatables' or custom DRF endpoints.

Basic setup integrating with DataTables server-side processing.

# models.py
from django.db import models

class Person(models.Model):
    name = models.CharField(max_length=100)
    age = models.IntegerField()

# views.py
from dj_datatables.views import DatatableView
from .models import Person

class PersonListView(DatatableView):
    model = Person
    columns = ['name', 'age']

# urls.py
from django.urls import path
from .views import PersonListView

urlpatterns = [
    path('people/data/', PersonListView.as_view(), name='person_list'),
]

# template.html
<table id="my-table" class="table">
  <thead>
    <tr>
      <th>Name</th>
      <th>Age</th>
    </tr>
  </thead>
</table>
<script>
$(document).ready(function() {
    $('#my-table').DataTable({
        serverSide: true,
        ajax: '{% url "person_list" %}',
        columns: [
            { data: 'name' },
            { data: 'age' }
        ]
    });
});
</script>