Can't render json format data from views.py to django template to build DataTable
Can't render json format data from views.py to django template to build DataTable
Hi All,
Description of problem:
I have a Django project and I need to migrate DataTable there including child rows and so on.
I have followed the example below, built the table, sourced CSS, and js codes:
https://datatables.net/examples/api/row_details.html
But I faced the issue while rendering JSON format data from my views.py to Django template. In the page, I am getting an empty table and following warning message:
Error messages shown:
**DataTables warning: table id=table_id - Requested unknown parameter 'id' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4**
Debugger code:
https://debug.datatables.net/urewec
Link to test case:
It's run on my local server in Linux, so I Can't put the link, but I will show my codes
I have attached HTML, JS, views.py files
Could you please help me solve this issue?? I have investigated the cases from forums and looks like there is no such case there
Thanks
Answers
I don't think
"data": JSON.parse(JSON.stringify("{{ table }}")),
is going to work. There seems to be a few things wrong with this statement. I've not tried rendering data into the Javascript portion of the page this way so I'm not sure how it would work. I use Flask not Django and with my pages I have a route that renders the HTML page then another route that handles fetching the data via Ajax. I would do something like this:I think Django uses
JsonResponse
to return JSON data.You may need to fix the Python code as I'm not familiar with Django syntax and methods.
Take a look at the Data Sources docs and Ajax docs for more details.
Kevin
Hi Kevin,
Thank you so very much for the help, I have finally resolved the issue, and build the desired table
I have followed Data Sources docs and get the solution there
Once again, thank you, as your shared data helped me a lot
Regards,
Matso