flask.Flask.request_context¶
-
Flask.request_context(environ)[source]¶ Creates a
RequestContextfrom the given environment and binds it to the current context. This must be used in combination with thewithstatement because the request is only bound to the current context for the duration of thewithblock.Example usage:
with app.request_context(environ): do_something_with(request)
The object returned can also be used without the
withstatement which is useful for working in the shell. The example above is doing exactly the same as this code:ctx = app.request_context(environ) ctx.push() try: do_something_with(request) finally: ctx.pop()
Changed in version 0.3: Added support for non-with statement usage and
withstatement is now passed the ctx object.Parameters: environ – a WSGI environment