> >     def test(self, var):
> >         id = var
> >         if int(id) > 5:
> >             return 'GREATER THAN'
> >         else:
> >             return 'LESS THAN'
>
> You'll run into trouble here if var is '' or contains non-numeric
> characters.  Your default value in the routing rule is "novar", which
> would raise a ValueError exception and ultimately a "500 Internal
> Server Error".  Since we can't trust users to always put numeric
> values, you should trap the case thus:

Yeah, I know. The "novar" default was left over from passing strings
to the page via querystring. Like I said I'm just throwing stuff at
the framework right now to kind of "feel it out" and get a grip on how
it handles stuff.

Just to rule out the possibility that I did somthing wierd I created a
new project, added a new controller (changed nothing, its index action
returns 'Hello World', and just add the line to by BaseController to
print out the class name and received almost the same result:

CtestController
TemplateController
ErrorController
TemplateController
ErrorController
TemplateController
ErrorController
TemplateController
ErrorController

> Does it make a difference if you omit the trailing slash?

Nope.

> You mean the error controller itself is failing to return a page?

Here's my new test BaseController on the old project:

fp = open('dump.txt', 'w')

class BaseController(WSGIController):

    def __call__(self, environ, start_response):
        """Invoke the Controller"""
        # WSGIController.__call__ dispatches to the Controller method
        # the request is routed to. This routing information is
        # available in environ['pylons.routes_dict']
        fp.write(self.__class__.__name__ + ':\n\n')
        try:
            result = WSGIController.__call__(self, environ,
start_response)
            fp.write('\n'.join(result) + '\n\n')
            return result
        finally:
            Session.remove()

And here's the output file (sorry about the length):

HelloController:


GREATER THAN

TemplateController:

<html>

  <head><title>Not Found</title></head>

  <body>

    <h1>Not Found</h1>

    <p>The resource could not be found.

<br/>

<!--  --></p>

    <hr noshade>

    <div align="right">WSGI Server</div>

  </body>

</html>



TemplateController:

<html>

  <head><title>Not Found</title></head>

  <body>

    <h1>Not Found</h1>

    <p>The resource could not be found.

<br/>

<!--  --></p>

    <hr noshade>

    <div align="right">WSGI Server</div>

  </body>

</html>



TemplateController:

<html>

  <head><title>Not Found</title></head>

  <body>

    <h1>Not Found</h1>

    <p>The resource could not be found.

<br/>

<!--  --></p>

    <hr noshade>

    <div align="right">WSGI Server</div>

  </body>

</html>



ErrorController:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
 <title>Server Error 404</title>

<style type="text/css">
body {
  font-family: Helvetica, sans-serif;
}

table {
  width: 100%;
}

tr.header {
  background-color: #006;
  color: #fff;
}

tr.even {
  background-color: #ddd;
}

table.variables td {
  verticle-align: top;
  overflow: auto;
}

a.button {
  background-color: #ccc;
  border: 2px outset #aaa;
  color: #000;
  text-decoration: none;
}

a.button:hover {
  background-color: #ddd;
}

code.source {
  color: #006;
}

a.switch_source {
  color: #0990;
  text-decoration: none;
}

a.switch_source:hover {
  background-color: #ddd;
}

.source-highlight {
  background-color: #ff9;
}

</style>

<!-- CSS Imports -->
<link rel="stylesheet" href="/error/style/orange.css" type="text/css"
media="screen" />

<!-- Favorite Icons -->
<link rel="icon" href="/error/img/icon-16.png" type="image/png" />

<style type="text/css">
        .red {
            color:#FF0000;
        }
        .bold {
            font-weight: bold;
        }
</style>

</head>

<body id="documentation">
<!-- We are only using a table to ensure old browsers see the message
correctly -->

<noscript>
<div style="border-bottom: 1px solid #808080">
<div style="border-bottom: 1px solid #404040">
<table width="100%" border="0" cellpadding="0"
bgcolor="#FFFFE1"><tr><td valign="middle"><img src="/error/img/
warning.gif" alt="Warning" /></td><td>&nbsp;</td><td><span
style="padding: 0px; margin: 0px; font-family: Tahoma, sans-serif;
font-size: 11px">Warning, your browser does not support JavaScript so
you will not be able to use the interactive debugging on this page.</
span></td></tr></table>
</div>
</div>
</noscript>

    <!-- Top anchor -->
    <a name="top"></a>

    <!-- Logo -->
    <h1 id="logo"><a class="no-underline" href="http://
www.pylonshq.com"><img class="no-border" src="/error/img/logo.gif"
alt="Pylons" title="Pylons"/></a></h1>
    <p class="invisible"><a href="#content">Skip to content</a></p>

    <!-- Main Content -->

    <div id="nav-bar">

        <!-- Section Navigation -->
        <h4 class="invisible">Section Links</h4>

            <ul id="navlist">
                <li class="active"><a href="#" accesskey="1"
class="active">Error 404</a></li>
            </ul>
    </div>
    <div id="main-content">

        <div class="hr"><hr class="hr" /></div>

        <div class="content-padding">

            <div id="main_data">
                <div style="float: left; width: 100%; padding-bottom:
20px;">
                <h1 class="first"><a name="content"></a>Error 404</h1>
                </div>

                NOT FOUND

            </div>

        </div>


            <!-- Footer -->

        <div class="hr"><hr class="clear" /></div>
    </div>

    <div style=" background: #FFFF99; padding: 10px 10px 10px 6%;
clear: both;">
        The Pylons Team |
        <a href="#top" accesskey="9" title="Return to the top of the
navigation links">Top</a>
    </div>
</body>
</html>


ErrorController:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
 <title>Server Error 404</title>

<style type="text/css">
body {
  font-family: Helvetica, sans-serif;
}

table {
  width: 100%;
}

tr.header {
  background-color: #006;
  color: #fff;
}

tr.even {
  background-color: #ddd;
}

table.variables td {
  verticle-align: top;
  overflow: auto;
}

a.button {
  background-color: #ccc;
  border: 2px outset #aaa;
  color: #000;
  text-decoration: none;
}

a.button:hover {
  background-color: #ddd;
}

code.source {
  color: #006;
}

a.switch_source {
  color: #0990;
  text-decoration: none;
}

a.switch_source:hover {
  background-color: #ddd;
}

.source-highlight {
  background-color: #ff9;
}

</style>

<!-- CSS Imports -->
<link rel="stylesheet" href="/error/style/orange.css" type="text/css"
media="screen" />

<!-- Favorite Icons -->
<link rel="icon" href="/error/img/icon-16.png" type="image/png" />

<style type="text/css">
        .red {
            color:#FF0000;
        }
        .bold {
            font-weight: bold;
        }
</style>

</head>

<body id="documentation">
<!-- We are only using a table to ensure old browsers see the message
correctly -->

<noscript>
<div style="border-bottom: 1px solid #808080">
<div style="border-bottom: 1px solid #404040">
<table width="100%" border="0" cellpadding="0"
bgcolor="#FFFFE1"><tr><td valign="middle"><img src="/error/img/
warning.gif" alt="Warning" /></td><td>&nbsp;</td><td><span
style="padding: 0px; margin: 0px; font-family: Tahoma, sans-serif;
font-size: 11px">Warning, your browser does not support JavaScript so
you will not be able to use the interactive debugging on this page.</
span></td></tr></table>
</div>
</div>
</noscript>

    <!-- Top anchor -->
    <a name="top"></a>

    <!-- Logo -->
    <h1 id="logo"><a class="no-underline" href="http://
www.pylonshq.com"><img class="no-border" src="/error/img/logo.gif"
alt="Pylons" title="Pylons"/></a></h1>
    <p class="invisible"><a href="#content">Skip to content</a></p>

    <!-- Main Content -->

    <div id="nav-bar">

        <!-- Section Navigation -->
        <h4 class="invisible">Section Links</h4>

            <ul id="navlist">
                <li class="active"><a href="#" accesskey="1"
class="active">Error 404</a></li>
            </ul>
    </div>
    <div id="main-content">

        <div class="hr"><hr class="hr" /></div>

        <div class="content-padding">

            <div id="main_data">
                <div style="float: left; width: 100%; padding-bottom:
20px;">
                <h1 class="first"><a name="content"></a>Error 404</h1>
                </div>

                NOT FOUND

            </div>

        </div>


            <!-- Footer -->

        <div class="hr"><hr class="clear" /></div>
    </div>

    <div style=" background: #FFFF99; padding: 10px 10px 10px 6%;
clear: both;">
        The Pylons Team |
        <a href="#top" accesskey="9" title="Return to the top of the
navigation links">Top</a>
    </div>
</body>
</html>


ErrorController:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
 <title>Server Error 404</title>

<style type="text/css">
body {
  font-family: Helvetica, sans-serif;
}

table {
  width: 100%;
}

tr.header {
  background-color: #006;
  color: #fff;
}

tr.even {
  background-color: #ddd;
}

table.variables td {
  verticle-align: top;
  overflow: auto;
}

a.button {
  background-color: #ccc;
  border: 2px outset #aaa;
  color: #000;
  text-decoration: none;
}

a.button:hover {
  background-color: #ddd;
}

code.source {
  color: #006;
}

a.switch_source {
  color: #0990;
  text-decoration: none;
}

a.switch_source:hover {
  background-color: #ddd;
}

.source-highlight {
  background-color: #ff9;
}

</style>

<!-- CSS Imports -->
<link rel="stylesheet" href="/error/style/orange.css" type="text/css"
media="screen" />

<!-- Favorite Icons -->
<link rel="icon" href="/error/img/icon-16.png" type="image/png" />

<style type="text/css">
        .red {
            color:#FF0000;
        }
        .bold {
            font-weight: bold;
        }
</style>

</head>

<body id="documentation">
<!-- We are only using a table to ensure old browsers see the message
correctly -->

<noscript>
<div style="border-bottom: 1px solid #808080">
<div style="border-bottom: 1px solid #404040">
<table width="100%" border="0" cellpadding="0"
bgcolor="#FFFFE1"><tr><td valign="middle"><img src="/error/img/
warning.gif" alt="Warning" /></td><td>&nbsp;</td><td><span
style="padding: 0px; margin: 0px; font-family: Tahoma, sans-serif;
font-size: 11px">Warning, your browser does not support JavaScript so
you will not be able to use the interactive debugging on this page.</
span></td></tr></table>
</div>
</div>
</noscript>

    <!-- Top anchor -->
    <a name="top"></a>

    <!-- Logo -->
    <h1 id="logo"><a class="no-underline" href="http://
www.pylonshq.com"><img class="no-border" src="/error/img/logo.gif"
alt="Pylons" title="Pylons"/></a></h1>
    <p class="invisible"><a href="#content">Skip to content</a></p>

    <!-- Main Content -->

    <div id="nav-bar">

        <!-- Section Navigation -->
        <h4 class="invisible">Section Links</h4>

            <ul id="navlist">
                <li class="active"><a href="#" accesskey="1"
class="active">Error 404</a></li>
            </ul>
    </div>
    <div id="main-content">

        <div class="hr"><hr class="hr" /></div>

        <div class="content-padding">

            <div id="main_data">
                <div style="float: left; width: 100%; padding-bottom:
20px;">
                <h1 class="first"><a name="content"></a>Error 404</h1>
                </div>

                NOT FOUND

            </div>

        </div>


            <!-- Footer -->

        <div class="hr"><hr class="clear" /></div>
    </div>

    <div style=" background: #FFFF99; padding: 10px 10px 10px 6%;
clear: both;">
        The Pylons Team |
        <a href="#top" accesskey="9" title="Return to the top of the
navigation links">Top</a>
    </div>
</body>
</html>


HelloController:


GREATER THAN

TemplateController:

<html>

  <head><title>Not Found</title></head>

  <body>

    <h1>Not Found</h1>

    <p>The resource could not be found.

<br/>

<!--  --></p>

    <hr noshade>

    <div align="right">WSGI Server</div>

  </body>

</html>



TemplateController:

<html>

  <head><title>Not Found</title></head>

  <body>

    <h1>Not Found</h1>

    <p>The resource could not be found.

<br/>

<!--  --></p>

    <hr noshade>

    <div align="right">WSGI Server</div>

  </body>

</html>



ErrorController:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
 <title>Server Error 404</title>

<style type="text/css">
body {
  font-family: Helvetica, sans-serif;
}

table {
  width: 100%;
}

tr.header {
  background-color: #006;
  color: #fff;
}

tr.even {
  background-color: #ddd;
}

table.variables td {
  verticle-align: top;
  overflow: auto;
}

a.button {
  background-color: #ccc;
  border: 2px outset #aaa;
  color: #000;
  text-decoration: none;
}

a.button:hover {
  background-color: #ddd;
}

code.source {
  color: #006;
}

a.switch_source {
  color: #0990;
  text-decoration: none;
}

a.switch_source:hover {
  background-color: #ddd;
}

.source-highlight {
  background-color: #ff9;
}

</style>

<!-- CSS Imports -->
<link rel="stylesheet" href="/error/style/orange.css" type="text/css"
media="screen" />

<!-- Favorite Icons -->
<link rel="icon" href="/error/img/icon-16.png" type="image/png" />

<style type="text/css">
        .red {
            color:#FF0000;
        }
        .bold {
            font-weight: bold;
        }
</style>

</head>

<body id="documentation">
<!-- We are only using a table to ensure old browsers see the message
correctly -->

<noscript>
<div style="border-bottom: 1px solid #808080">
<div style="border-bottom: 1px solid #404040">
<table width="100%" border="0" cellpadding="0"
bgcolor="#FFFFE1"><tr><td valign="middle"><img src="/error/img/
warning.gif" alt="Warning" /></td><td>&nbsp;</td><td><span
style="padding: 0px; margin: 0px; font-family: Tahoma, sans-serif;
font-size: 11px">Warning, your browser does not support JavaScript so
you will not be able to use the interactive debugging on this page.</
span></td></tr></table>
</div>
</div>
</noscript>

    <!-- Top anchor -->
    <a name="top"></a>

    <!-- Logo -->
    <h1 id="logo"><a class="no-underline" href="http://
www.pylonshq.com"><img class="no-border" src="/error/img/logo.gif"
alt="Pylons" title="Pylons"/></a></h1>
    <p class="invisible"><a href="#content">Skip to content</a></p>

    <!-- Main Content -->

    <div id="nav-bar">

        <!-- Section Navigation -->
        <h4 class="invisible">Section Links</h4>

            <ul id="navlist">
                <li class="active"><a href="#" accesskey="1"
class="active">Error 404</a></li>
            </ul>
    </div>
    <div id="main-content">

        <div class="hr"><hr class="hr" /></div>

        <div class="content-padding">

            <div id="main_data">
                <div style="float: left; width: 100%; padding-bottom:
20px;">
                <h1 class="first"><a name="content"></a>Error 404</h1>
                </div>

                NOT FOUND

            </div>

        </div>


            <!-- Footer -->

        <div class="hr"><hr class="clear" /></div>
    </div>

    <div style=" background: #FFFF99; padding: 10px 10px 10px 6%;
clear: both;">
        The Pylons Team |
        <a href="#top" accesskey="9" title="Return to the top of the
navigation links">Top</a>
    </div>
</body>
</html>


ErrorController:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
 <title>Server Error 404</title>

<style type="text/css">
body {
  font-family: Helvetica, sans-serif;
}

table {
  width: 100%;
}

tr.header {
  background-color: #006;
  color: #fff;
}

tr.even {
  background-color: #ddd;
}

table.variables td {
  verticle-align: top;
  overflow: auto;
}

a.button {
  background-color: #ccc;
  border: 2px outset #aaa;
  color: #000;
  text-decoration: none;
}

a.button:hover {
  background-color: #ddd;
}

code.source {
  color: #006;
}

a.switch_source {
  color: #0990;
  text-decoration: none;
}

a.switch_source:hover {
  background-color: #ddd;
}

.source-highlight {
  background-color: #ff9;
}

</style>

<!-- CSS Imports -->
<link rel="stylesheet" href="/error/style/orange.css" type="text/css"
media="screen" />

<!-- Favorite Icons -->
<link rel="icon" href="/error/img/icon-16.png" type="image/png" />

<style type="text/css">
        .red {
            color:#FF0000;
        }
        .bold {
            font-weight: bold;
        }
</style>

</head>

<body id="documentation">
<!-- We are only using a table to ensure old browsers see the message
correctly -->

<noscript>
<div style="border-bottom: 1px solid #808080">
<div style="border-bottom: 1px solid #404040">
<table width="100%" border="0" cellpadding="0"
bgcolor="#FFFFE1"><tr><td valign="middle"><img src="/error/img/
warning.gif" alt="Warning" /></td><td>&nbsp;</td><td><span
style="padding: 0px; margin: 0px; font-family: Tahoma, sans-serif;
font-size: 11px">Warning, your browser does not support JavaScript so
you will not be able to use the interactive debugging on this page.</
span></td></tr></table>
</div>
</div>
</noscript>

    <!-- Top anchor -->
    <a name="top"></a>

    <!-- Logo -->
    <h1 id="logo"><a class="no-underline" href="http://
www.pylonshq.com"><img class="no-border" src="/error/img/logo.gif"
alt="Pylons" title="Pylons"/></a></h1>
    <p class="invisible"><a href="#content">Skip to content</a></p>

    <!-- Main Content -->

    <div id="nav-bar">

        <!-- Section Navigation -->
        <h4 class="invisible">Section Links</h4>

            <ul id="navlist">
                <li class="active"><a href="#" accesskey="1"
class="active">Error 404</a></li>
            </ul>
    </div>
    <div id="main-content">

        <div class="hr"><hr class="hr" /></div>

        <div class="content-padding">

            <div id="main_data">
                <div style="float: left; width: 100%; padding-bottom:
20px;">
                <h1 class="first"><a name="content"></a>Error 404</h1>
                </div>

                NOT FOUND

            </div>

        </div>


            <!-- Footer -->

        <div class="hr"><hr class="clear" /></div>
    </div>

    <div style=" background: #FFFF99; padding: 10px 10px 10px 6%;
clear: both;">
        The Pylons Team |
        <a href="#top" accesskey="9" title="Return to the top of the
navigation links">Top</a>
    </div>
</body>
</html>






On Nov 20, 4:30 pm, "Mike Orr" <[EMAIL PROTECTED]> wrote:
> On Nov 20, 2007 12:02 PM, Justin <[EMAIL PROTECTED]> wrote:
>
> > Thank you both for your responses. Right now, I'm just evaluating the
> > framework to see if it seems like a good fit so the controller doesn't
> > do much
>
> We like troubleshooting small, simple examples. :)
>
> >     def test(self, var):
> >         id = var
> >         if int(id) > 5:
> >             return 'GREATER THAN'
> >         else:
> >             return 'LESS THAN'
>
> You'll run into trouble here if var is '' or contains non-numeric
> characters.  Your default value in the routing rule is "novar", which
> would raise a ValueError exception and ultimately a "500 Internal
> Server Error".  Since we can't trust users to always put numeric
> values, you should trap the case thus:
>
>     if not var.isdigit():
>         return "Third URL component must be numeric."
>
> >     map.connect('hello/test/:var', controller='hello', action='test',
> > var="novar")
> > Requested url:
>
> >http://localhost:5000/hello/test/10/
>
> Does it make a difference if you omit the trailing slash?
>
> > I also printed out the return value of each controller called and the
> > error controllers are returning a 404 page each time.
>
> You mean the error controller itself is failing to return a page?
>
> --
> Mi
ke Orr <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to