本文共 953 字,大约阅读时间需要 3 分钟。
class HeaderData(View): def get(self, request): # 获取用户发来数据类型 type1 = request.META.get('CONTENT_TYPE') print(type1) # 获取cookie cookie = request.COOKIES print(cookie) # 获取用户上传的文件 files = request.FILES print(files) # 获取用户请求的url path = request.path print(path) # 获取请求方式 method = request.method print(method) # 获取用户信息 user = request.user print(user) return HttpResponse('success')
打印台输出
class TestJsonData(View): def get(self, request): # 创建一个response对象,可自定义状态码 res = HttpResponse('asfsd', status=200) return res def post(self, request): # 创建一个json字典 data_dict = { 'name': 'rong', 'age': 19 } # 创建一个JsonResponse参数为json字典 json_data = JsonResponse(data_dict) # 返回JsonResponse对象 return json_data
测试
转载地址:http://tmuhf.baihongyu.com/