The util module is accessible via the pylons.controllers module.
etag_cache, redirect_to, and abort.
Aborts the request immediately by returning an HTTP exception
In the event that the status_code is a 300 series error, the detail attribute will be used as the Location header should one not be specified in the headers attribute.
Use the HTTP Entity Tag cache for Browser side caching
If a "If-None-Match" header is found, and equivilant to key, then a 304 HTTP message will be returned with the ETag to tell the browser that it should use its current cache of the page.
Otherwise, the ETag header will be added to the response headers.
Suggested use is within a Controller Action like so:
1 2 3 4 5 6 | import pylons class YourController(BaseController): def index(self): etag_cache(key=1) return render('/splash.mako') |
Note
This works because etag_cache will raise an HTTPNotModified exception if the ETag recieved matches the key provided.
Raises a redirect exception
Optionally, a _code variable may be passed with the status code of the redirect, ie:
1 | redirect_to('home_page', _code=303) |
Deprecated A Response object can be passed in as _response which will have the headers and cookies extracted from it and added into the redirect issued.
See the source for more information.