1. cherrypy
  2. CherryPy
Issue #283 resolved

Support Localized/Custom HTTP error messages.

created an issue

Currently, http errors result in english messages based on the messages built into the python HTTP Server. It would be nice to return localized messages based on the browser's Accept-Language or the server configuration.

It would also be nice if the errors supported basic conditional expressions based on the server configuration. This would allow error pages to contain links back to the refering page, or administrator contact issue.

Comments (6)

  1. Anonymous

    I have come up with a very basic, that only supports conditional substitutions.

    Sample template

    <h2>404 Not Found</h2>
      No file could be found at <a href="$request_path">$request_path</a>
    #if referer
       You may wish to contact the webmaster of <a href="$referer">$referer</a> and ask them to update their site.
    #elif foobar

    If blocks can not be nested and #if/elif/else/endif, must come at the beginning of the line.

  2. Robert Brewer

    _cputil.getErrorPage can receive arbitrary keyword-args, which will be interpolated into the template (which is also overridable). However, HTTPError doesn't yet support ''sending'' such arguments.

  3. Anonymous

    this does not really solve the problem. also other content then text/html is requested for (see ticket 340). for now i do a cherrypy._cputil._HTTPErrorTemplate = '... which is somehow ugly. would be nice to include this in config to have different pages/mimetypes by path which would also resolve 340.

  4. Anonymous

    I assume that if someone wants to spend time on changing the language of an error sent by its CP application, he would also spend time changing the overall layout to integrate it to its application.

    Therefore externalising the default template doesn't look like the right approach to me. In fact one can totally do what one wants already by implementing specific _cp_on_error and _cp_on_http_error handlers. Those are flexible enough to change CP error handling behavior.

    Maybe the book should provide more examples about it though.

    I think we should close this issue as invalid.

  5. Log in to comment