#2086: style the 404
------------------------+---------------------------------------------------
 Reporter:  faide       |        Owner:  faide
     Type:  task        |       Status:  new  
 Priority:  high        |    Milestone:  2.0b3
Component:  TurboGears  |      Version:  trunk
 Severity:  normal      |   Resolution:       
 Keywords:              |  
------------------------+---------------------------------------------------
Comment (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.

-- 
Ticket URL: <http://trac.turbogears.org/ticket/2086#comment:6>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "TurboGears Tickets" group.
This group is read-only. No posting by normal members allowed.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears-tickets?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to