我发现这段代码可以让 Bottle 中的路由以与 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)
我正在尝试将name
传递给页面视图功能。浏览了 Bottle 的源代码后,我看不到如何name
将其发送到该函数,甚至无法看到为什么要使用它。