标签:HttpRequest 返回 Http 请求 23 text 2019.03 HttpResponse response
自己也要分清楚 看清楚 request,response
一个是请求 一个是相应
行 头 之间还有个空行 体
HttpRequest请求对象(只读)
-
当用户访问一个视图函数时,Django会创建一个request对象(HttpRequest)
-
HttpRequest对象中封装了所有的Http协议中的请求信息
常见属性和方法
HttpRequest.scheme:返回协议类型(http/https)
HttpRequest.body:返回请求实体内容
HttpRequest.path:返回请求地址
HttpRequest.method:返回当前请求方式(GET/POST)
HttpRequest.GET:返回当前请求参数的字典QueryDict
HttpRequest.POST:返回当前请求参数的字典QueryDict
HttpRequest.COOKIES:返回客户端所有的cookie信息
HttpRequest.FILES:获取上传文件(1.要求POST请求2.enctype="multipart/form-data)
HttpRequest.META:返回请求报文信息
HttpRequest.get_host():返回请求主机名和端口号
HttpRequest.get_full_path():返回请求地址(包括请求参数)
HttpResponse 响应对象
用法
#响应内容
>>> from django.http import HttpResponse
>>> response = HttpResponse("Here's the text of the Web page.")
>>> response = HttpResponse("Text only, please.", content_type="text/plain")
>>> response = HttpResponse()
>>> response.write("<p>Here's the text of the Web page.</p>")
>>> response.write("<p>Here's another paragraph.</p>")
>>> response = HttpResponse(my_data, content_type='application/vnd.ms-excel')
>>> response['Content-Disposition'] = 'attachment; filename="foo.xls"'
#设置响应头信息
response = HttpResponse('hello')
response.__setitem__('hello','123')
response = HttpResponse('hello')
response['uname']='zhangsan'
response.setdefault('Server','WBS')
标签:HttpRequest,返回,Http,请求,23,text,2019.03,HttpResponse,response 来源: https://www.cnblogs.com/Py-king/p/10583395.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。