bottle.py URL路由和反向howto?

est*_*est 1 python url-routing bottle

样本Bottle.py代码:

@route('/show_<name>')
def show(name):
   return ''
Run Code Online (Sandbox Code Playgroud)

我的问题是:

  1. 给定一个URL,我们如何获得视图功能?例如,URL是/show_magic,我需要知道该show()函数负责此请求URL

  2. 给定路由(不是路由器!!)和参数,如何获取URL?例如,我需要一个名为reverse的函数reverse(default_app().routes[0], name='me') == '/show_me'

Mua*_*adi 6

您可能想要考虑命名路线

@route('/show_<item_name>', name='item_show')
def show(item_name):
   return ''
Run Code Online (Sandbox Code Playgroud)

现在给出路由名称和params如何获取URL?我们使用get_url

get_url('item_show', item_name='my_item')
Run Code Online (Sandbox Code Playgroud)

http://nongraphical.com/2012/08/using-bottle-py-in-production/