python version: 2.7.10
django version: 1.9
rest framework 3.3.2
安裝
pip install django
pip install djangorestframework
settings.py installed_apps中引入rest_framework
建立model, 修改mdels.py
建立serializers.py
restore_object() 3.0以上版本不支援已經被create()和update()方法代替,源碼如下:
建立基于類和函數的視圖
urls.py配置
apiview
generic通用視圖
post請求被定義為建立“從屬資源”(擁有父資源的資源) (add)
參考文章:
<a href="http://www.lifelaf.com/blog/?p=156" target="_blank">http://www.lifelaf.com/blog/?p=156</a>
<a href="http://s3.51cto.com/wyfs02/m01/78/6d/wkiom1z755yiv9hxaabo7ft4pkm974.png" target="_blank"></a>