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 (the the output above was from calling the "test" action that
I was using to test accessing route variables):
class HelloController(BaseController):
def index(self):
# Return a rendered template
# return render('/some/template.mako')
# or, Return a response
return 'Hello World!'
def test(self, var):
id = var
if int(id) > 5:
return 'GREATER THAN'
else:
return 'LESS THAN'
My routes:
def make_map():
"""Create, configure and return the routes Mapper"""
map = Mapper(directory=config['pylons.paths']['controllers'],
always_scan=config['debug'])
# The ErrorController route (handles 404/500 error pages); it
should
# likely stay at the top, ensuring it can always be resolved
map.connect('error/:action/:id', controller='error')
# CUSTOM ROUTES HERE
map.connect('hello/test/:var', controller='hello', action='test',
var="novar")
map.connect(':controller/:action/:id')
map.connect('*url', controller='template', action='view')
return map
Requested url:
http://localhost:5000/hello/test/10/
Base controller:
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']
try:
return WSGIController.__call__(self, environ,
start_response)
finally:
Session.remove()
print self.__class__
I also printed out the return value of each controller called and the
error controllers are returning a 404 page each time. However, the
browser returns "GREATER THAN" as expected.
On Nov 20, 2:45 pm, "Mike Orr" <[EMAIL PROTECTED]> wrote:
> On Nov 20, 2007 11:05 AM, Justin <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Sorry, I got cut off.. Anyway, the order is as follows:
>
> > 1. <my test controller>
> > 2. template.TemplateController
> > 3. template.TemplateController
> > 4. error.ErrorController
> > 5. template.TemplateController
> > 6. error.ErrorController
> > 7. error.ErrorController
>
> > This is for a test view that just returns a simple string to the
> > browser and the page is returned as is should be without error. Is
> > this normal? What is the purpose of all these controller calls? Right
> > now I'm just evaluating pylons but this strikes me as inefficient and
> > obtuse.
>
> Are you sure it's not making all those requests, perhaps for images or
> stylesheets? I tried what you said, putting
>
> print "Controller is", self.__class__.__name__
>
> at the beginning of BaseController.__call__() in one of my
> applications, It prints the expected controller, not the extra lines.
> But if I go to a nonexistent page, I get this:
>
> Controller is TemplateController
> Controller is ErrorController
> Controller is ErrorController
> Controller is ErrorController
> Controller is ErrorController
> Controller is ErrorController
> Controller is ErrorController
> Controller is ErrorController
>
> TemplateController is the one in your last routing rule, which matches
> if no other routes have matched. By default it always reports "404
> Not Found". This is caught by the ErrorDocuments middleware, which
> makes a subrequest for the error page -- the first ErrorController
> call. The other ErrorController calls are stylesheets and images for
> that page.
>
> If you still can't figure it out, show us your controller class, any
> changes you've made to the routing, and the URL you're requesting, and
> maybe that will clear it up.
>
> --
> Mike 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
-~----------~----~----~----~------~----~------~--~---