Published in 09:11 of 08/12/2012 by

Published in 09:11 of 08/12/2012

←Home

web2py routes

customizing routes in web2py

web2py comes with defaults for url routes, the default configuration uses the following pattern

http://host:port//<controller name>/<function name>/args/?vars=value

Sometimes we need to change it to a better and beauty URL like

http://host:port/<controller name>/<function name>
or even
http://host:port/<function name>

thats how to to it

Put those lines in /web2py/routes.py - if you have an application called myapp this would be

# -*- coding: utf-8 -*-

routers = dict(
# base router
    BASE=dict(
        default_application='myapp',
    ),
    # app specific router
    myapp=dict(
        default_controller='home',
        default_function='index'
    )
)

logging = 'print'

# routes_onerror = [
#     (r'myapp/404', r'/myapp/static/fail404.html'),
#     (r'myapp/*', r'/myapp/static/fail.html'),
#     (r'*/404', r'/myapp/static/cantfind.html'),
#     (r'*/*', r'/myapp/error/index'),
# ]

error_message = ('<html><body>'
                  '<strong>ERROR DETECTED </strong>'
                  '<h1>%s</h1>'
                  '</body></html>')

error_message_ticket = ('<html><body><h1>Internal error</h1>Ticket issued:'
                         '<a href="/admin/default/ticket/%(ticket)s"'
                         ' target="_blank">%(ticket)s</a>'
                         '<h1>ERROR DETECTED</h1>'
                         '</body></html>')
  • O Natal Animal 2013 está no ar in Home · 23:24 of 12/10/2013
  • Desenvolvendo protótipos para startups com Python e web2py in web2py · 20:25 of 11/19/2013
  • Gravando logs de aplicativos web2py in web2py · 00:29 of 01/21/2013

  • comments powered by Disqus Go Top