This QueryDict instance is immutable

后端 未结 5 1099
夕颜
夕颜 2020-12-30 06:10

I have a Branch model with a foreign key to account (the owner of the branch):

class Branch(SafeDeleteModel):
    _safedelete_policy = SOFT_DELETE_CASCADE
           


        
5条回答
  •  醉酒成梦
    2020-12-30 06:34

    As you can see in the Django documentation:

    The QueryDicts at request.POST and request.GET will be immutable when accessed in a normal request/response cycle.

    so you can use the recommendation from the same documentation:

    To get a mutable version you need to use QueryDict.copy()

    or ... use a little trick, for example, if you need to keep a reference to an object for some reason or leave the object the same:

    # remember old state
    _mutable = data._mutable
    
    # set to mutable
    data._mutable = True
    
    # сhange the values you want
    data['param_name'] = 'new value'
    
    # set mutable flag back
    data._mutable = _mutable
    

    where data it is your QueryDicts

提交回复
热议问题