req.get("bar").get("baz")
only works if the first get
returns a dictionary with the right key
In [182]: req = {'bar': {'baz': 'foo'}}
In [183]: req.get('bar')
Out[183]: {'baz': 'foo'}
In [184]: req.get('bar').get('baz')
Out[184]: 'foo'
That is the second get
applies to the object returned by the first.
In [185]: req = { "foo": True }
In [186]: req.get('bar')
# returned None
Another way to write this would be:
req['bar']['baz'] # req must be a nested dictionary
get
takes a default
, which could be another dictionary. In fact it could return the dictionary itself - repeatedly:
In [187]: req.get('bar', req)
Out[187]: {'foo': True}
In [188]: req.get('bar', req).get('baz')
In [189]: req.get('bar', req).get('baz', req)
Out[189]: {'foo': True}
In [190]: req.get('bar', req).get('baz', req).get('foo')
Out[190]: True
This would return your NotFound
:
In [193]: req.get('bar', {}).get('baz', 'fppbar')
Out[193]: 'fppbar'