views.py 视图中的常见操作

views.py 视图中的常见操作

request

  • 请求路径 request.path
  • 请求方式 request.method
  • 请求协议 request.schema
  • 请求服务器主机信息 request.get_host()
  • 请求服务器端口信息 request.get_port()
  • 请求参数

request.GET : 只能接收以 get 形式提交的参数
GET 形式的参数:在地址上以 ? 分割,
有 key=value 组成,
多个参数用 & 分割
request.POST : 接收以 post 形式提交的参数

request.GET, request.POST 返回的都是 QueryDict对象

QueryDict 常见的方法有:

  • get(key , default=None)

    • 获取单值、如果key 对应的是多值、只会获取最后一个值
  • getlist(key, default=None)

    • 获取多值
  • dict()

    • 如果参数中有多值的操作、会只回去最后一个

response

render(request, template_name)

猜你喜欢

转载自www.cnblogs.com/hylone/p/11848270.html