>
> The web2py book and documentation has led me to believe that the following 
> would work;
>
> http://120.0.0.1/myapp/default/somefunction can be written as 
> http://120.0.0.1/myapp/somefunction but I get invalid request error
>

Here's what the book says:

web2py maps a URL of the form:

1.

http://127.0.0.1:8000/a/c/f.html

to the function f() in controller "c.py" in application "a". If f is not 
present, web2py defaults to the indexcontroller function. If c is not 
present, web2py defaults to the "default.py" controller, and if a is not 
present, web2py defaults to the init application. If there is no init 
application, 
web2py tries to run the welcomeapplication.

I think I see the confusion. It says if the controller is not present, 
web2py defaults to the default.py controller. However, when you have the 
URL /myapp/somefunction, technically the controller is present, as web2py 
will interpret the second element of the URL as the controller (just 
because you know somefunction is a function doesn't mean the default router 
does) -- in that case, it's actually the function that is missing, not the 
controller. So, what the above really means is:

/myapp maps to /myapp/default/index
/myapp/default maps to /myapp/default/index

but /myapp/somefunction does not map to /myapp/default/somefunction because 
somefunction is interpreted as a controller in that URL (instead, it maps 
to /myapp/somefunction/index, and you get an error because such a 
controller doesn't exist).
 

> If I then overwrite routes.py using routes.example.py, the above case no 
> longer works. Looking at both routes.example.py and router.example.py, it 
> looks like both of them configure web2py's routing behavior in the same 
> way, but the actual behavior is not the same.
>

I assume you're referring to the default_controller='default' parameter set 
in the routes.example.py example. I agree that's a little confusing because 
you might expect it to work much like setting the default controller in the 
parameter-based system, but again, let's look at what the book says:

When using the pattern-based system, the name of the default application, 
controller, and function can be changed from *init*, *default*, and *index* 
respectively 
to another name by setting the appropriate value in routes.py 


That's saying that setting the value of default_controller merely changes 
the default value used by the standard routing system when that item is 
missing from the URL. So, let's say you set 
default_controller='mycontroller'. In that case, /myapp would map to 
/myapp/mycontroller/index instead of /myapp/default/index, but 
/myapp/somefunction would still cause a problem because somefunction would 
be seen as a controller.

One thing to note is that the parameter-based system was created quite a 
while after the pattern-based system, so seemingly similar functionality 
wasn't necessarily designed to behave the same way (hopefully the behavior 
of the parameter-based system is seen as an improvement in this case).

Anyway, I agree some of this could be better explained in the book.

Anthony

Reply via email to