forked from orbit-oss/flask
Changed interface for flask.g
This now makes it behave like it did before, it's just an object. It did however gain ``__contains__`` and ``__iter__`` and I added a ``get()`` method to fetch an attribute without raising an error. This fixes #759.
This commit is contained in:
parent
efd6e468ae
commit
c889fbc231
4 changed files with 29 additions and 19 deletions
|
|
@ -276,12 +276,12 @@ thing, like it does for :class:`request` and :class:`session`.
|
|||
is especially useful when combined with the :ref:`faking-resources`
|
||||
pattern for testing.
|
||||
|
||||
Additionally as of 0.10 you can use the subscription operator syntax to
|
||||
get an attribute or `None` if it's not set. These two usages are now
|
||||
equivalent::
|
||||
Additionally as of 0.10 you can use the :meth:`get` method to
|
||||
get an attribute or `None` (or the second argument) if it's not set.
|
||||
These two usages are now equivalent::
|
||||
|
||||
user = getattr(flask.g, 'user', None)
|
||||
user = flask.g['user']
|
||||
user = flask.g.get('user', None)
|
||||
|
||||
This is a proxy. See :ref:`notes-on-proxies` for more information.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue