|
List Info
Thread: Redirecting 404 requests to a handler in CherryPy 3.0.2
|
|
| Redirecting 404 requests to a handler
in CherryPy 3.0.2 |

|
2007-12-16 15:50:46 |
Greetings,
I'm in the process of upgrading to CherryPy 3 from 2.2. One
of the
things that seems to have disappeared in the new version is
the
_cp_on_http_error method for handling custom errors. I used
to be able
to do this:
def _cp_on_http_error(self, status, message):
cherrypy.response.body = [self.customError()] #call
an
internal method that would render out some html.
I have diligently read the manual, tried writing a custom
tool on the
'after_error_response' hook, read the code and googled my
heart out,
but I have no idea how to do this in 3.
Any help?
-c
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: Redirecting 404 requests to a
handler in CherryPy 3.0.2 |

|
2007-12-17 07:50:17 |
On 12/16/07, Cory <corbinrsmith gmail.com> wrote:
> I'm in the process of upgrading to CherryPy 3 from 2.2.
One of the
> things that seems to have disappeared in the new
version is the
> _cp_on_http_error method for handling custom errors. I
used to be able
> to do this:
>
> def _cp_on_http_error(self, status, message):
> cherrypy.response.body = [self.customError()]
#call an
> internal method that would render out some html.
>
> I have diligently read the manual, tried writing a
custom tool on the
> 'after_error_response' hook, read the code and googled
my heart out,
> but I have no idea how to do this in 3.
>
> Any help?
Try setting request.error_page in your config. Here is the
docstring
for that attribute:
"""
A dict of {error code: response filename} pairs. The
named response
files should be Python string-formatting templates, and
can expect by
default to receive the format values with the mapping
keys 'status',
'message', 'traceback', and 'version'. The set of format
mappings
can be extended by overriding HTTPError.set_response.
"""
HTH,
Christian
http://www.dowski.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: Redirecting 404 requests to a
handler in CherryPy 3.0.2 |

|
2007-12-17 10:39:09 |
|
Thanks, but that isn't quite what I'm looking to do...
I have actual business logic that makes suggestions for different pages, so a static template with a few replacement variables isn't going to quite carry it.
Though, I suppose I could monkey-patch NotFound.set_response, but I'm not thrilled about it.
I did finally get something that worked, but it is always doing a check on before_finalize, which seems a tad wasteful.
def not_found_redirect(path): if cherrypy.response.status == 404 and cherrypy.request.path_info != path: raise cherrypy.InternalRedirect(path)
cherrypy.tools.not_found_redirect = cherrypy.tools.Tool
('before_finalize', not_found_redirect)
-c
On Dec 17, 2007 5:50 AM, Christian Wyglendows ki < christian dowski.com">christian dowski.com> wrote:
On 12/16/07, Cory < corbinrsmith gmail.com">corbinrsmith gmail.com> wrote: > I'm in the process of upgrading to CherryPy 3 from 2.2. One of the > things that seems to have disappeared in the new version is the
> _cp_on_http_error method for handling custom errors. I used to be able > to do this: > > def _cp_on_http_error(self, status, message): > cherrypy.response.body = [self.customError()] #call an
> internal method that would render out some html. > > I have diligently read the manual, tried writing a custom tool on the > 'after_error_response' hook, read the code and googled my heart out,
> but I have no idea how to do this in 3. > > Any help?
Try setting request.error_page in your config. Here is the docstring for that attribute: """ A dict of {error code: response filename} pairs. The named response
files should be Python string-formatting templates, and can expect by default to receive the format values with the mapping keys 'status', ';message9;, 'traceback', and 'version'. The set of format mappings
can be extended by overriding HTTPError.set_response. """
HTH,
Christian http://www.dowski.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users googlegroups.com To unsubscribe from this group, send email to cherrypy-users-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~---
|
[1-3]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|