与由DJango自动创建的HttpRequest对象相比, HttpResponse对象是我们的职责范围了. 我们写的每个视图都需要实例化, 填充和返回一个HttpResponse.
HttpResponse类位于django.http模块中.

1. 使用

传递字符串

from django.http import HttpResponse
response = HttpResponse("Here's the text of the Web page")
response = HttpResponse("Test only, please.", content_type="text/plain")

设置或删除响应头信息

response = HttpResponse()
response["COntent-Type"] = "text/html; charset=UTF-8"
def response["Content-Type"]

2. 属性

HttpResponse.content: 响应内容
HttpResponse.charset: 响应内容的编码
HttpResponse.status_code: 响应的状态码

相关文章:

  • 2021-12-12
  • 2022-12-23
  • 2021-12-18
  • 2022-02-14
  • 2021-11-28
  • 2022-12-23
  • 2021-08-08
猜你喜欢
  • 2022-12-23
  • 2021-05-27
  • 2022-12-23
  • 2021-08-13
  • 2021-07-27
相关资源
相似解决方案