Error when I try to assign a value to a key in a dict Python-Django

1

I'm doing a function and I'm taking out values from the request. I made a response variable which has 3 nodes to fill. This is the function

from django.http import HttpResponse as hres
import json

def go( req ):
    res = {
        'success':'',
        'message':'',
        'data':'',
    }

multiple = req.POST['mult']
value = req.POST['value']
if multiple is True and value == '':
    res.success = False
    res.message = 'No llegó el valor a buscar'
    res.data = None
else:
    res.success = True
    res.message = 'Se buscó correctamente'
    res.data = None
return hres( json.dumps( res ) )

I see this error

  

AttributeError at fakePath 'dict' object has not attibute 'success'

I do not understand, in fact I only declared my variable so

res = {}

According to me, as long as the key does not exist in the first level, the same system creates it (or, at least, it happens in Javascript)

What am I ignoring?

    
asked by Alberto Siurob 28.08.2018 в 22:54
source

0 answers