[Answered ]-Authomatic: REQUEST is deprecated / The returned state doesn't match with the stored state

2👍

Here’s my own version, which may not be the best, but is v2 and v3 python compatible, and solves the main problem of iterlists(): this function always returns an array, even where there’s only one item. So authomatic makes a comparison between a string and “an array with one item” and thus fails. My solution: if only an array with one item, just keep this item, not the array.

@property
def params(self):
    # (!) Olivier Pons ! REQUEST removed
    a = QueryDict('', mutable=True)
    a.update(self.request.GET)
    a.update(self.request.POST)
    retour = {}
    for key, value in a.iterlists():
        if len(value) > 1:
            retour[key] = value
        else:
            retour[key] = value[0]
    return retour

0👍

Another possible solution:

@property
def params(self):
    if self.request.method == 'POST':
        return dict(self.request.POST)
    else:
        return dict(self.request.GET)

Update: Previous code is not equivalent to old request.RESQUEST

It can be used QueryDict.dict():

@property
def params(self):
    a = self.request.POST.copy()
    a.update(self.request.GET)
    return(a.dict())

0👍

Thanks @Oliver Ponus, I am new to DJango..Finally your answer e helped me. But if you pass list value as a parameter this method will not take the full data . So I have done small modification make it work

for key, value in item_value.items():
  if len(value) > 1:
        retour[key]=item_value.getlist(key) 
  else:
        retour[key] = value[0]

Leave a comment