diff options
author | Ryan Petrello <lists@ryanpetrello.com> | 2014-02-18 09:46:08 -0500 |
---|---|---|
committer | Ryan Petrello <lists@ryanpetrello.com> | 2014-02-18 09:49:07 -0500 |
commit | a6d5395770fb50f3590ee493cbd03a652a127d20 (patch) | |
tree | 4ed402e0bf33b9a1d49fa6cfae8c7c47721831ec /docs/source | |
parent | 1335f2c19dbfff0bd586d4ea6071cedf69b5c36f (diff) | |
download | pecan-a6d5395770fb50f3590ee493cbd03a652a127d20.tar.gz |
Add improved documentation for `pecan.request` and `pecan.response`.
Change-Id: I6f27e5a352000758b959f70d19261389a3ea97b7
Closes-Bug: 1276869
Diffstat (limited to 'docs/source')
-rw-r--r-- | docs/source/routing.rst | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/docs/source/routing.rst b/docs/source/routing.rst index da8c785..ec79305 100644 --- a/docs/source/routing.rst +++ b/docs/source/routing.rst @@ -267,6 +267,34 @@ routing system on top of Pecan, defining a base controller class that defines a :func:`_route` method will enable you to have total control. +Interacting with the Request and Response Object +------------------------------------------------ + +For every HTTP request, Pecan maintains a thread-local reference to the request +and response object, ``pecan.request`` and ``pecan.response``. These are +instances of :class:`webob.request.BaseRequest` and +:class:`webob.response.Response`, respectively, and can be interacted with from +within Pecan controller code:: + + @pecan.expose() + def login(self): + assert pecan.request.path == '/login' + username = pecan.request.POST.get('username') + password = pecan.request.POST.get('password') + + pecan.response.status_int = 403 + pecan.response.body = 'Bad Login!' + +While Pecan abstracts away much of the need to interact with these objects +directly, there may be situations where you want to access them, such as: + +* Inspecting components of the URI +* Determining aspects of the request, such as the user's IP address, or the + referer header +* Setting specific response headers +* Manually rendering a response body + + Mapping Controller Arguments ---------------------------- |