Re: [web2py] Re: routes.py and rewriting URLs
On Aug 15, 2011, at 2:40 PM, Anthony wrote: > On Monday, August 15, 2011 5:14:01 PM UTC-4, Jonathan Lundell wrote: > On Aug 15, 2011, at 11:38 AM, Anthony wrote: > >> You should also be able to go to /admin/default/reload_routes to reload >> routes.py, but it looks like there is currently a bug that is causing that >> to fail. >> > > Any idea why (or how)? > > It calls gluon.rewrite.load() without importing gluon.rewrite. I submitted a > patch to Massimo. > Ah, thanks.
Re: [web2py] Re: routes.py and rewriting URLs
On Monday, August 15, 2011 5:14:01 PM UTC-4, Jonathan Lundell wrote: > > On Aug 15, 2011, at 11:38 AM, Anthony wrote: > > You should also be able to go to /admin/default/reload_routes to reload > routes.py, but it looks like there is currently a bug that is causing that > to fail. > > > Any idea why (or how)? > It calls gluon.rewrite.load() without importing gluon.rewrite. I submitted a patch to Massimo. Anthony
Re: [web2py] Re: routes.py and rewriting URLs
On Aug 15, 2011, at 1:20 PM, fishwebby wrote: > I tried your suggestion, with routes.py in the web2py directory, but > alas it didn't work. Not sure what I'm doing wrong (nice suggestion > about the print statement though to make sure it's working). You can also revise the doctests in routes.py to match your rules, and use that for some basic testing.
Re: [web2py] Re: routes.py and rewriting URLs
On Aug 15, 2011, at 11:38 AM, Anthony wrote: > You should also be able to go to /admin/default/reload_routes to reload > routes.py, but it looks like there is currently a bug that is causing that to > fail. > Any idea why (or how)?
[web2py] Re: routes.py and rewriting URLs
I'm a newbie and I try to avoid at all costs using routes.py just to re-organize my controllers. It's much safer, easier and predictable to organize controllers and functions to map directly to URLs. If you are moving from another system and want to make sure old users continue to be supported, that's a reasonable reason to use routes.py like this.
[web2py] Re: routes.py and rewriting URLs
I tried your suggestion, with routes.py in the web2py directory, but alas it didn't work. Not sure what I'm doing wrong (nice suggestion about the print statement though to make sure it's working). Hmm... On Aug 15, 8:06 pm, Rufus wrote: > I'm a newbie too, but I see myself also "prettying" up my > URL's with routes.py. > > Is your routes.py in the correct directory? If it is in > an application directory, it won't work. it should be in > the web2py directory. > > A hint: You can always put print statements in any of your .py files > to verify they are being executed. > > For your example, I would guess routes.py would look like: > > --- > routes_in = ( ('admin/courses','init/admin_courses/index'),) > routes_out = ( ('init/admin_courses/index', 'admin/courses'),) > print "routing lists initialized..." > --- > > and it would be in your web2py directory. > > (...time passes, trying it out) > > I discovered one other thing! If you edit routes.py, SHUTDOWN AND > RESTART WEB2PY! > > The routing lists are initted at web2py startup, not on every http > request! > > Rufus > > On Aug 14, 6:26 am, fishwebby wrote: > > > > > > > > > Hi, > > > I'm struggling with the routing in web2py and I'm hoping someone can > > point me in the right direction (I'm a web2py newbie). > > > I want to change this (which works): > > >http://127.0.0.1:8000/init/admin_courses/index > > > to this: > > >http://127.0.0.1:8000/admin/courses > > > but I can't get it to work with the various routes.py files. I've > > followed the suggestions here:http://wiki.web2py.com/URL_Re_writing > > and here:http://www.web2py.com/book/default/chapter/04#URL-Rewrite > > > and various others from this forum but I can't get anything other than > > "invalid request". > > > I want to do this for various controllers, for example: > > >http://127.0.0.1:8000/admin/usershttp://127.0.0.1:8000/admin/users/3/... > > > (I'm coming from Rails / Symfony / Kohana so perhaps I'm trying to do > > something that isn't the web2py way?) > > > If anyone can point me in the right direction it would be greatly > > appreciated! > > > Many thanks > > Dave
[web2py] Re: routes.py and rewriting URLs
On Monday, August 15, 2011 2:06:23 PM UTC-4, Rufus wrote: > > For your example, I would guess routes.py would look like: > > --- > routes_in = ( ('admin/courses','init/admin_courses/index'),) > routes_out = ( ('init/admin_courses/index', 'admin/courses'),) > print "routing lists initialized..." > --- And be careful -- if you want to be able to access the 'admin' app that comes with web2py, make sure your routes still allow that. > I discovered one other thing! If you edit routes.py, SHUTDOWN AND > RESTART WEB2PY! You can also do: import gluon.rewrite gluon.rewrite.load() You should also be able to go to /admin/default/reload_routes to reload routes.py, but it looks like there is currently a bug that is causing that to fail. Anthony
[web2py] Re: routes.py and rewriting URLs
I'm a newbie too, but I see myself also "prettying" up my URL's with routes.py. Is your routes.py in the correct directory? If it is in an application directory, it won't work. it should be in the web2py directory. A hint: You can always put print statements in any of your .py files to verify they are being executed. For your example, I would guess routes.py would look like: --- routes_in = ( ('admin/courses','init/admin_courses/index'),) routes_out = ( ('init/admin_courses/index', 'admin/courses'),) print "routing lists initialized..." --- and it would be in your web2py directory. (...time passes, trying it out) I discovered one other thing! If you edit routes.py, SHUTDOWN AND RESTART WEB2PY! The routing lists are initted at web2py startup, not on every http request! Rufus On Aug 14, 6:26 am, fishwebby wrote: > Hi, > > I'm struggling with the routing in web2py and I'm hoping someone can > point me in the right direction (I'm a web2py newbie). > > I want to change this (which works): > > http://127.0.0.1:8000/init/admin_courses/index > > to this: > > http://127.0.0.1:8000/admin/courses > > but I can't get it to work with the various routes.py files. I've > followed the suggestions here:http://wiki.web2py.com/URL_Re_writing > and here:http://www.web2py.com/book/default/chapter/04#URL-Rewrite > > and various others from this forum but I can't get anything other than > "invalid request". > > I want to do this for various controllers, for example: > > http://127.0.0.1:8000/admin/usershttp://127.0.0.1:8000/admin/users/3/assignments > > (I'm coming from Rails / Symfony / Kohana so perhaps I'm trying to do > something that isn't the web2py way?) > > If anyone can point me in the right direction it would be greatly > appreciated! > > Many thanks > Dave
[web2py] Re: routes.py and rewriting URLs
Ok, it's good to know I'd need to use the pattern-matching router and not the parametric one. Basically what I'm trying to do is avoid having all my controllers in the one directory - in a recent Kohana project for example I had them split up in different subdirectories, according to user role: admin, manager etc. So for now I'll just have to have controllers called admin_courses, admin_users, admin_files etc. and have those in the URLs - when I've got more time I'll work out how to change the URLs (which shouldn't affect how the app works if I don't hard code any URLs I'm assuming) On Aug 14, 6:08 pm, Jonathan Lundell wrote: > On Aug 14, 2011, at 3:26 AM, fishwebby wrote: > > > I'm struggling with the routing in web2py and I'm hoping someone can > > point me in the right direction (I'm a web2py newbie). > > > I want to change this (which works): > > >http://127.0.0.1:8000/init/admin_courses/index > > > to this: > > >http://127.0.0.1:8000/admin/courses > > You could probably figure out how to do this eventually using the > pattern-matching router (the parametric router won't do it for you), but it's > going to be a lot easier if you start out without the need to rename/split > controller items. > > It's hard to say what would work best without knowing more about the patterns > you'd see and the controllers and functions you have. > > > > > > > > > > > but I can't get it to work with the variousroutes.pyfiles. I've > > followed the suggestions here: > >http://wiki.web2py.com/URL_Re_writing > > and here: > >http://www.web2py.com/book/default/chapter/04#URL-Rewrite > > > and various others from this forum but I can't get anything other than > > "invalid request". > > > I want to do this for various controllers, for example: > > >http://127.0.0.1:8000/admin/users > >http://127.0.0.1:8000/admin/users/3/assignments > > > (I'm coming from Rails / Symfony / Kohana so perhaps I'm trying to do > > something that isn't the web2py way?) > > > If anyone can point me in the right direction it would be greatly > > appreciated!