Python Bottle Image第2部分

时间:2011-12-07 12:27:33

标签: python image static bottle

我不确定,如果我没有正确理解瓶子教程但是这段代码:

from bottle import static_file

@route('/images/<filename:re:.*\.png>')
def send_image(filename):
    return static_file(filename, root='/path/to/image/files', mimetype='image/png')

应该查看该图像名称的文件夹,而不必在名称中添加.png,对吗?

所以如果我有一个名为python.png的文件

我会输入浏览器... / python,这应该让我得到图像,对吗?

因为我没有得到图像但是当我向它添加.png时我确实得到了它

1 个答案:

答案 0 :(得分:3)

好吧,回答你在评论中提出的问题......

@route('/images/:filename')
def send_image(filename):
    return static_file(filename + '.png', root='/path/to/image/files', mimetype='image/png')