• 简介
      在正常的请求/响应周期中访问时,request.POST和request.GET上的QueryDict将是不可变的.
      要获得可变版本,您需要使用QueryDict.copy()或者._mutable = True
  • 第一种方式
      用request.POST调用_mutable并修改为True
      reuqets.POST._mutable = True
  • 第二种方式 copy方法
      <QueryDict: {'title': ['水浒传2'], 'price': ['12.00'], 'pub_date': ['2020-07-03'], 'pub_id': ['2'], 'authors': ['2', '4']}>
      data = request.POST.copy()
      xx = data.pop('authors')  #此时就可以用删除方法删除querydict中的数据了
      print(xx) #['2', '4']

将querydict类型转换为普通字典

      data = request.POST.dict()
      <QueryDict: {'title': ['水浒传2'], 'price': ['12.00'], 'pub_date': ['2020-07-03'], 'pub_id': ['2'], 'authors': ['2', '4']}>
      {'title': '水浒传2', 'price': '12.00', 'pub_date': '2020-07-03', 'pub_id': '1', 'authors': '4'}

相关文章:

  • 2021-09-07
  • 2021-09-17
  • 2021-06-10
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-30
  • 2021-12-22
  • 2021-10-31
  • 2021-11-28
  • 2021-11-28
  • 2021-08-20
  • 2022-12-23
相关资源
相似解决方案