On Friday, June 30, 2017 at 4:24:35 PM UTC-4, Brendan Barnwell wrote:
>
> On Thursday, June 29, 2017 at 8:27:01 AM UTC-7, Anthony wrote:
>>
>> You need to have at least a basic routes.py in the root /web2py folder, 
>> but for application specific routing, you can also put a routes.py file in 
>> the application folder (i.e., in /web2py/applications/myapp/).
>>
>
> Okay. . . but so I guess that means the answer to my question is "no".  
> What you're saying is that there is a no way for an application to control 
> its own internal routing without support from a routes.py that has to be 
> installed separately, outside the application folder.
>

Right, though the routes.py in the /web2py root folder can include just a 
single generic line, and it only needs to be set up once, when web2py is 
initially installed. You would never have to make any changes to that file, 
and each app could then have its own routes.py and completely control its 
own routes.

Is this a problem? Are you developing an app that you must distribute to 
environments you don't control and where it would be difficult to put in 
place a single standard routes.py file?
 

> Do I understand right from the documentation that any routes that are not 
> matched by routes.py will behave just as they would if routes.py were not 
> present?  So in other words, if I have an app that wants to do internal 
> routing, can I be sure that a global routes.py containing just:
>
> routes_app = [
>     ('/myapp/*', 'myapp')
> ]
>
> . . . will not affect any app but 'myapp'?  (And thus, if I have multiple 
> applications that want their own rewrite schemes, I would just add their 
> entries to the routes_app?)
>

If you just want to leave the app name in place as the first segment of the 
URL, you don't even need a rule for each app -- you just need a single rule 
that matches any app and then routes to that matched app name. For the 
parameter-based system, this is even easier -- you just need something as 
simple as:

router = {}

  I guess what I don't understand is why I need to re-define the default 
> behavior in this way.  Is there a reason web2py doesn't look for the 
> app-specific routes.py once it knows what app is requested, even if there 
> is no global routes.py?  Is it just to avoid the performance hit of doing 
> this check all the time?
>

The routes are loaded once when web2py first starts (they can be reloaded 
via admin or by restarting the server, but they are not loaded at every 
request). But I suppose in theory web2py could look in the app folders for 
app-specific routes files even in the absence of a root routes.py file. 
Maybe make a pull request if that is important to you.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to