Hyphen in application name

53 views
Skip to first unread message

tim.n...@conted.ox.ac.uk

unread,
Dec 15, 2014, 5:42:53 AM12/15/14
to web...@googlegroups.com
Does anyone know how to get map_hyphen to work with an application name?

I have a routes.py setup as follows:

routers = dict(
   BASE  = dict(        
       default_application = "home",
       default_controller = "default",
       default_function = "index",
       map_hyphen=True,
        ),
   
)

In my application (tutor_events), controller and function hyphen mapping work fine, so the following paths work:
/tutor_events/default/edit-details/424
/tutor_events/tutor-fee/add

And all URLs are being generated with hyphens

But if I try to go to /tutor-events/..., I get an error: invalid function (default/tutor_events)

So web2py is trying to send me on to /home/default/tutor_events

Derek

unread,
Dec 15, 2014, 7:27:03 PM12/15/14
to web...@googlegroups.com
well, according to the documentation it should work, so perhaps you encountered a bug. 

Just a question, where did you put your routes.py? if in the application, then you can only route controllers and functions.

tim.n...@conted.ox.ac.uk

unread,
Dec 16, 2014, 4:39:36 AM12/16/14
to web...@googlegroups.com
I've put Routes.py in the root web2py directory.  You may be right about a bug, though.  I've loaded up a fresh local copy of web2py, created an app called a_b, and set up the routing:

routers = dict(

    # base router
    BASE=dict(
        default_application='welcome',
        map_hyphen=True,
    ),
)

All the static files fail, and http://127.0.0.1:8000/a-b returns "invalid function (default/a_b)"

tim.n...@conted.ox.ac.uk

unread,
Dec 16, 2014, 5:09:43 AM12/16/14
to web...@googlegroups.com
After some further digging, I'm not sure map_hyphens can possibly work on application names as things sit.

In map_app() in rewrite.py, the incoming app name is never translated.  I added the following code near the top of the function, and everything started to work.

        if routers.BASE.map_hyphen:
            arg0 = self.harg0.replace('-', '_')
        else:
            arg0 = self.harg0


Reply all
Reply to author
Forward
0 new messages