I have found this code which enables routes in Bottle to be stored in a similar way to Django:
from bottle import route
# Assuming your *_page view functions are defined above somewhere
urlpatterns = (
# (path, func, name)
('/', home_page, 'home'),
('/about', about_page, 'about'),
('/contact', contact_page, 'contact'),
)
for path, func, name in urlpatterns:
route(path, name=name)(func)
I’m trying to get the name passed to the page view functions. Having gone through the source code of Bottle I cannot see how name can be sent to the function or even why it is used if it cannot be sent.
The name is used to reference other pages (e.g. for
app.get_url). The name of the current request callback is available throughrequest['bottle.route'].name. Besides, you can use theroute(..., callback=...)argument to avoid the double-call of the decorator.