# routes.py
import os, re
default_app = 'crm'
routes_in = []
regex = re.compile('^\w+$')
for app in os.listdir('applications'):
if regex.match(app):
routes_in.append(('/%s' % app, '/%s/default' % app))
routes_in.append(('/%s/(?P<path>.*)' % app, '/%s/\g<path>' %
app))
routes_out = (
('/%s/static/(?P<path>.*)' % default_app, '/static/\g<path>'),
('/%s/default/(?P<path>.*)' % default_app, '/\g<path>'),
)
routes_in.extend(
[(y.replace('\g<path>', '(?P<path>.*)'), x.replace('(?P<path>.*)',
'\g<path>')
) for (x, y) in routes_out]
)
Its working very good for me. And I can browse the list_companies page
with both urls http://crm.appspot.com/crm/default/list_companies and
http://crm.appspot.com/list_companies.
Does it have any performance overhead? Else why the routes.py is not
preferred?
On Jan 6, 9:32 pm, Sujan Shakya <suzan.sha...@gmail.com> wrote:
> I want to share my routes.py file. The case is that I want only one
> application to be hosted on my site and I want to keep my urls clean.
> So instead of having urlhttp://crm.appspot.com/crm/default/list_persons,
> I want to have url likehttp://crm.appspot.com/list_persons. In order
> to achieve this behavior, I wrote the routes.py as:
>
> # routes.py
> import os, re
>
> default_app = 'crm'
>
> routes_in = []
>
> regex = re.compile('^\w+$')
> for app in os.listdir('applications'):
> if regex.match(app):
> routes_in.append(('/%s' % app, '/%s/default' % app))
> routes_in.append(('/%s/(?P<path>.*)' % app, '/%s/\g<path>' %
> app))
>
> routes_out = (
> ('/%s/static/(?P<path>.*)' % default_app, '/static/\g<path>'),
> ('/%s/default/(?P<path>.*)' % default_app, '/\g<path>'),
> )
>
> routes_in.extend(
> [(y.replace('\g<path>', '(?P<path>.*)'), x.replace('(?P<path>.*)',
> '\g<path>')
> ) for (x, y) in routes_out]
> )
>
> Its working very good for me. And I can browse the list_companies page
> with both urlshttp://crm.appspot.com/crm/default/list_companiesandhttp://crm.appspot.com/list_companies.