/DRF-dataTable-Example-server-side

DataTables Example (server-side) - Python Django REST framework

Primary LanguageHTMLMIT LicenseMIT

DRF-dataTable-Example-server-side

DataTables Example (server-side) - Python Django REST framework

DataTables (server-side) 搭配 Django REST framework 簡單範例 📝

特色

安裝套件

請在你的命令提示字元 (cmd ) 底下輸入

安裝 Django

pip install django

安裝 Django-REST-framework

pip install djangorestframework

安裝 django-model-utils

pip install django-model-utils

或是使用 cmd (命令提示字元)

pip install -r requirements.txt

說明

  • LOG 資訊非常重要,可以參考官網 django logging , 或是看範例裡面的 settings.py 裡面的 LOGGING。

  • 建議透過 django-db-backends 來觀看目前的 orm 到底執行了什麼 SQL 指令,可以到範例裡面的 settings.py 找 django.db.backends。

執行方法

使用命令提示字元 ( cmd ) 輸入下方指令

python manage.py runserver

然後瀏覽

http://127.0.0.1:8000/index/

執行畫面

首頁

[Get] api/music/{額外 DataTables 參數}

alt tag

新增

[POST] api/music/

alt tag

編輯

[PUT] api/music/{id}/

alt tag

刪除

[DELETE] api/music/{id}/

alt tag

搜尋 排序

[Get] api/music/{ 額外 DataTables 參數 }

alt tag

後記

  • 從影片中的 demo 可以很明顯的看出當資料量很大(5 萬筆)的時候,如果沒有用 server-side 的方式,而是一次全部載入,使用者體驗非常差。

  • 本範例前後端並沒有分離,而是寫在一起,比較好的方式,應該是前後端分離。

  • api document 可參考 api_document.html ,直接用瀏覽器開啟即可。 ( 文件教學可參考 aglio_tutorial )

執行環境

  • Python 3.4.3

Reference

Donation

文章都是我自己研究內化後原創,如果有幫助到您,也想鼓勵我的話,歡迎請我喝一杯咖啡:laughing:

alt tag

贊助者付款

License

MIT license