I'm trying to use rest in conjunction with Datatables to display a large list with server-side processing. On the datatable html template i get an empty table with an error
"DataTables warning: table id=bib - Ajax error. For more information about this error, please see http://datatables.net/tn/7".
urls.py
from . import views as v
from rest_framework import routers
router = routers.DefaultRouter()
router.register(r'Bibrest51', v.BibViewSet)
urlpatterns = [
path('home/', include(router.urls)),
path('home/', v.home, name='home'),
path('', v.home, name='home'),
views.py
class Get_bib(viewsets.ModelViewSet):
queryset = Bibrest51.objects.all()
serializer_class = BibSerializer
home.html
<table id="bib" class="table table-striped table-bordered" style="width:100%" data-server-side="true"
data-ajax="/home/Bibrest51/?format=datatables">
<thead>
<tr>
<th data-data="autor" class ="text-center all">Autor</th>
<th data-data="ano" class ="text-center all">Ano</th>
<th>Título</th>
<th data-data="tipo" class ="text-center not-mobile">Tipo</th>
<th data-data="tema" class ="text-center not-mobile">Tema</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
JS:
<script>
$(document).ready(function() {
$('#bib').DataTable();
});
</script>
models.py
class Bibrest51(models.Model):
cadastro_id = models.AutoField(primary_key=True)
autor = models.CharField(db_column='Autor', max_length=255)
ano = models.CharField(db_column='Ano', max_length=255)
titulo = models.CharField(db_column='Titulo', max_length=255)
referencia = models.CharField(db_column='Referencia', max_length=255)
serializers.py
from rest_framework import serializers
from .models import Bibrest51
class BibSerializer(serializers.ModelSerializer):
class Meta:
model = Bibrest51
fields = ['autor', 'ano','tipo','tema']