django - 請求和響應
django 中,使用的 request 是 WSGIRequest (傳統的request)
request.GET , request.POST
django 中, 使用的 response 有:
HttpResponse() : 可以返回一個 普通的字符串,也可以實現文件的下載
render() : 跳轉到一個模板頁面中
redirect() : 重定向到一個 請求/路由 中
JsonResponse() : 響應一個 JSON格式的數據
drf 中的請求和響應
使用 drf 中的 request,需要在 視圖函數中添加 @api_view
- 接受 POST , PUT , PATCH 的參數, 推薦使用 request.data
- 接受 GET , DELETE 的參數 , 推薦 使用 request.query_params
使用 drf 中 的 response , 需要在 視圖函數中添加 @api_view
from rest_framework.response import Response