Need help with routes

49 views
Skip to first unread message

Vinicius Assef

unread,
Sep 29, 2015, 8:57:14 PM9/29/15
to web2py
Hi there.

Routes is an area in Web2py I never really understood. :-(

I need your help.

I have the following routes.py in web2py.dir:

```
# web2py/routes.py
# -*- coding: utf-8 -*-

logging = 'debug'

default_application = 'myapp'

routes_app = ((r'/(?P<app>welcome|admin)\b.*', r'\g<app>'),
              (r'(.*)', r'myapp'),
              (r'/?(.*)', r'myapp'))
```

As you can see, I delegate urls for `myapp` to `myapp/routes.py` below:

```
# web2py/applications/myapp/routes.py
# -*- coding: utf-8 -*-

app = '/myapp'

routes_in = (
    ('/$c/$f', app + '/$c/$f'),
    ('/$c/$f/$anything', app + '/$c/$f/$anything'),
)

routes_out = [(to, from_) for (from_, to) in routes_in]
```

This structure allows me to have the url `http://localhost:8000/default/index` correctly routed. But it fails with I have an URL with extension: `http://localhost:8000/default/index.html`

Every URL with the extension fails.

BTW, I found this problem with $name notation when trying to load components from a view with `LOAD(c="default", f="mycomponent.load", ajax=True)`.

Then, now I have my routes.py with regular expressions working like a charm:

```
app = '/myapp'

routes_in = (
    ('/(?P<any>.*)', app + '/\g<any>'),
)

routes_out = (
    (app + '/(?P<any>.*)', '/\g<any>'),
)
```

What am I doing wrong with $name notation? Or it cannot handle extensions? Or it is a bug?

--
Vinicius Assef.

Vinicius Assef

unread,
Sep 29, 2015, 9:43:35 PM9/29/15
to web2py
SOLVED.

I found this question [1] from 2010 and this is still causing some confusion. :-(

I just fixed my routes.py as you can see below:

```
# web2py/applications/myapp/routes.py
# -*- coding: utf-8 -*-

app = '/myapp'

routes_in = (
    ('/$anything', app + '/$anything'),
)

routes_out = (
    (app + '/$anything', '/$anything'),
)
```

--
Vinicius.
Reply all
Reply to author
Forward
0 new messages