This commit is contained in:
Kenneth Reitz
2010-10-20 11:22:49 -07:00
parent a04274f652
commit f8b78768fa
-39
View File
@@ -79,42 +79,3 @@ To install ``pip``: ::
Hopefully you'll never have to use **easy_install** again.
.. Firing Before/After Request
.. ::::::::::::::::::::::::::-
..
.. By just creating a request context, you still don't have run the code that
.. is normally run before a request. This probably results in your database
.. being unavailable, the current user not being stored on the
.. :data:`~flask.g` object etc.
..
.. This however can easily be done yourself. Just call
.. :meth:`~flask.Flask.preprocess_request`:
..
.. >>> ctx = app.test_request_context()
.. >>> ctx.push()
.. >>> app.preprocess_request()
..
.. Keep in mind that the :meth:`~flask.Flask.preprocess_request` function
.. might return a response object, in that case just ignore it.
..
.. To shutdown a request, you need to trick a bit before the after request
.. functions (triggered by :meth:`~flask.Flask.process_response`) operate on
.. a response object:
..
.. >>> app.process_response(app.response_class())
.. <Response 0 bytes [200 OK]>
.. >>> ctx.pop()
Further Improving the Shell Experience
::::::::::::::::::::::::::::::::::::::
If you like the idea of experimenting in a shell, create yourself a module
with stuff you want to star import into your interactive session. There
you could also define some more helper methods for common things such as
initializing the database, dropping tables etc.
Just put them into a module (like `shelltools` and import from there):
>>> from shelltools import *