Skip to content
Myr

Documented changes on the g object some more

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 1f6be7f · Browse files · 3 files+24 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+24 added−1 removed

  • other:+24 added−1 removed

3 files+24 added−1 removed

modified:docs/api.rst+10 added-1 removed
270 unmodified lines
271 connection or the user that is currently logged in.272273 Starting with Flask 0.10 this is stored on the application context and274 no longer on the request context which means it becomes available if275 only the application context is bound and not yet a request.275 only the application context is bound and not yet a request. This276 is especially useful when combined with the :ref:`faking-resources`277 pattern for testing.278279 Additionally as of 0.10 you can use the subscription operator syntax to280 get an attribute or `None` if it's not set. These two usages are now281 equivalent::282283 user = getattr(flask.g, 'user', None)284 user = flask.g['user']285286 This is a proxy. See :ref:`notes-on-proxies` for more information.287288289Useful Functions and Classes
454 unmodified lines
modified:docs/testing.rst+1 added
248 unmodified lines
249250This in general is less useful because at that point you can directly251start using the test client.252253.. _faking-resources:254255Faking Resources and Context256----------------------------257
95 unmodified lines
modified:flask/testsuite/basic.py+13 added
1114 unmodified lines
1115 c.get('/success')1116 self.assert_equal(len(errors), 3)1117 self.assert_equal(errors[1], None)11181119 def test_subscript_syntax_on_g(self):1120 app = flask.Flask(__name__)1121 app.testing = True11221123 with app.app_context():1124 self.assert_equal(flask.g['x'], None)1125 flask.g.x = 421126 self.assert_equal(flask.g['x'], 42)1127 self.assert_equal(flask.g.x, 42)1128 flask.g['x'] = 231129 self.assert_equal(flask.g['x'], 23)1130 self.assert_equal(flask.g.x, 23)113111321133class SubdomainTestCase(FlaskTestCase):11341135 def test_basic_support(self):1136 app = flask.Flask(__name__)
77 unmodified lines