django-datatables-view
raw JSON → 1.20.0 verified Mon Apr 27 auth: no python
A Django library that provides server-side processing for DataTables jQuery plugin with minimal configuration. Version 1.20.0 supports Django 5.0, last updated in 2023. Release cadence is sporadic.
pip install django-datatables-view Common errors
error NoReverseMatch at /datatable/ ↓
cause Missing URL name or misconfigured urls.py
fix
Ensure your URL pattern has a name attribute and is referenced correctly in templates.
error AttributeError: 'MyModelDatatableView' object has no attribute 'model' ↓
cause Forgetting to set 'model' attribute on the view
fix
Add 'model = MyModel' inside your DatatableView subclass.
error Column 'name' not found on model ↓
cause Column name in 'columns' doesn't match a model field or annotated expression
fix
Verify that each column name corresponds to a model field, property, or annotate() expression.
Warnings
breaking In version 1.10.0, the import path changed from 'datatables_view' to 'datatableview.views'. Old imports will break. ↓
fix Update imports: from datatableview.views import DatatableView
deprecated The 'display_fields' attribute is deprecated in favor of 'columns'. 'display_fields' may be removed in future. ↓
fix Use 'columns' instead of 'display_fields' in your view.
gotcha The library expects the URL's GET parameters to match DataTables' built-in parameters exactly. If you use a custom column name, you must map it via 'column_defs'. ↓
fix Use 'column_defs' dict in view to map DataTables column indices to model fields.
Imports
- DatatableView wrong
from datatables_view import DatatableViewcorrectfrom datatableview.views import DatatableView - X_DSW wrong
from datatableview import X_DSWcorrectfrom datatableview.views import X_DSW
Quickstart
# views.py
from datatableview.views import DatatableView
from .models import MyModel
class MyModelDatatableView(DatatableView):
model = MyModel
columns = ['id', 'name', 'created_at']
# urls.py
from django.urls import path
from .views import MyModelDatatableView
urlpatterns = [
path('datatable/', MyModelDatatableView.as_view(), name='datatable'),
]