DRF框架的安装与使用
DRF框架的安装与配置
"""
1)安装
>: pip install djangorestframework
2)在settings中注册(为什么要注册,后期会讲)
INSTALLED_APPS = [
# ...
'rest_framework',
]
3)在settings中自定义drf配置
REST_FRAMEWORK = {}
注:drf配置查找顺序,自定义settings的REST_FRAMEWORK配置字典 => drf默认settings的DEFAULTS
4)drf的封装特点:特点功能在特点模块下
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.request import Request
"""
基于restful接口规范的接口设计
urlpatterns = [
# 资源books接口的设计
url(r'^books/$', views.BookAPIView.as_view()), # 群查、单增
url(r'^books/(?P<pk>\d+)/$', views.BookAPIView.as_view()), # 单查、单删、单(整体|局部)改
]
选择了IT,必定终身学习