Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2086 (closed task: fixed)

Opened 10 years ago

Last modified 10 years ago

style the 404

Reported by: faide Owned by: faide
Priority: high Milestone: 2.0b5
Component: TurboGears Version: trunk
Severity: normal Keywords:
Cc:

Description

we need a nicer 404 error page

Change History

comment:1 Changed 10 years ago by mramm

  • Priority changed from normal to high

comment:2 Changed 10 years ago by mramm

This must be done in after #1677 is completed. At which point error.py will be a regular turbogears controller with no extra complexity.

--Mark Ramm

comment:3 Changed 10 years ago by mramm

  • Summary changed from style the 404 for beta1 to style the 404
  • Milestone changed from 2.0b1 to 2.0b2

comment:4 Changed 10 years ago by mramm

The pre-work for this is now done. And the page is now nicely styled in a pylons way, but we need to tg brand it.

comment:5 Changed 10 years ago by mramm

  • Milestone changed from 2.0b2 to 2.0b3

comment:6 Changed 10 years ago by jorge.vargas

I suggest we push this to the quickstart (everyone will want to publish his own 404 pages) for this I wrote some code to test it on a quickstarted project (patch will come if idea is accepted)

replace controllers/error.py with

import os.path

import tg

class ErrorController(object):
    """Generates error documents as and when they are required.

    The ErrorDocuments middleware forwards to ErrorController when error
    related status codes are returned from the application.

    This behaviour can be altered by changing the parameters to the
    ErrorDocuments middleware in your config/middleware.py file.
    """

    @tg.expose('fix.templates.error')
    def document(self):
        """Render the error document"""
        resp = tg.request.environ.get('pylons.original_response')
        return dict(code=tg.request.params.get('code', resp.status_int),
                    message=tg.request.params.get('message', resp.body))
        #return resp.body #3

then add the following template error.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">

  <xi:include href="master.html" />

<head>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
  <title>A ${code} Error has Occurred </title>
</head>

<body>
<h1>Error ${code}</h1>
<div>${message}</div>#1
<div>${XML(message)}</div>#2
</body>
</html>

This approach has several problems and it's really the way wsgi works. resp.body will return a "full response with <html> tags and all, as shown in line marked 1, therefore line 2 will generate a "page inside page" effect, on the other hand if we uncomment line 3 it will return a plan boring non-styled 404 page.

comment:7 follow-up: ↓ 8 Changed 10 years ago by mramm

I think the idea is good.

I'm not totally clear about the issue with the way WSGI works, seems more like we're doing something wrong with message.

I'm all for a patch because it'll be better than what we have now, and we can move forward from there.

comment:8 in reply to: ↑ 7 Changed 10 years ago by jorge.vargas

Replying to mramm:

I think the idea is good.

I'm not totally clear about the issue with the way WSGI works, seems more like we're doing something wrong with message.

yes indeed, I really don't know how to build up message unless I take resp.body and transform it into a node object, and take the bits out of it, I'll have to see if the ErrorMiddleware? has a way to return only the fragment of the response rather than the whole html tree.

I'm all for a patch because it'll be better than what we have now, and we can move forward from there.

ok I hate patches to quickstart they are awful to test, but since the overall idea is good I'll work from there.

comment:9 Changed 10 years ago by mramm

Basic styling is in, committed in #6226.

comment:10 Changed 10 years ago by mramm

  • Status changed from new to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.