【发布时间】:2014-06-10 12:12:15
【问题描述】:
我正在为每个请求在瓶子上编写一个模板。所以 localhost 和 locahost/mypage 和 localhost/mypage/about 将调用相同的模板。我在这里检查并找到了一些关于匹配所有 url 的好例子:
from bottle import route, run, template, static_file
@route("/<url:re:.+>")
def hello(url):
return template('page_template', url=url)
@route('/static/<filepath:path>', name='static')
def server_static(filepath):
return static_file(filepath, root='static')
run()
我的问题是: 1)它与根不匹配。所以如果我输入“localhost”,它就不起作用。 2)由于有静态文件,我有另一个静态文件服务的路线。因此,如果我键入 localhost/static/page,它不会返回“hello world”。
我相信我需要修改正则表达式 (/<:re:.>) 来处理这两种情况。任何帮助将不胜感激,
@迈克尔
【问题讨论】:
-
不太了解瓶子,但你需要一个“网址”吗? stackoverflow.com/a/8189597/792238
-
感谢您指出。我已经编辑过了,
-
(FTR,每个帖子最好问一个问题。)