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