django modifying the request object

后端 未结 4 1244
故里飘歌
故里飘歌 2020-11-30 07:10

I already have a django project and it logical like those:

url: URL?username=name&pwd=passwd

view:

def func(request):
   dic = request         


        
4条回答
  •  遥遥无期
    2020-11-30 07:47

    Remove immutability:

    if not request.GET._mutable:
       request.GET._mutable = True
    
    # now you can spoil it
    request.GET['pwd'] = 'iloveyou'
    

    Update

    The Django sanctioned way is: request.GET.copy().

    According to the docs:

    The QueryDicts at request.POST and request.GET will be immutable when accessed in a normal request/response cycle. To get a mutable version you need to use QueryDict.copy().

    Nothing guarantees future Django versions will use _mutable. This has more chances to change than the copy() method.

提交回复
热议问题