Datatables integration with django REST framework
Datatables integration with django REST framework
valafar
Posts: 1Questions: 1Answers: 0
I am a beginner in django framework and as well as in DataTables. Currently, I am trying to integrate the jquery DataTables plugin with django framework. I have built an api using django REST and I want to pass the data through this api to DataTables. Please find below my code snippets.
the index.html looks like following.
<table id="packages_table" class="table table-striped table-bordered">
<thead>
<tr>
<th>User Name</th>
<th>First Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function () {
$('#packages_table').dataTable({
ajax: 'http://127.0.0.1:3434/user/',
columns: [
{ "data": "username"},
{ "data": "first_name"},
{ "data": "email"},
]
});
});
</script>
The json from the url looks like this
[
{
"url": "http://127.0.0.1:3434/user/2/",
"username": "morgoth",
"first_name": "morgoth",
"email": "duke.valafar@gmail.com",
"is_staff": true
},
{
"url": "http://127.0.0.1:3434/user/3/",
"username": "anna",
"first_name": "",
"email": "anna@anna.com",
"is_staff": false
},
{
"url": "http://127.0.0.1:3434/user/4/",
"username": "adam",
"first_name": "",
"email": "ada@abc.com",
"is_staff": false
}
]
However, I am not able to load the table. Any help would be appreciated.
This discussion has been closed.