【问题标题】:Python Bottle Image part 2Python 瓶图像第 2 部分
【发布时间】:2011-12-07 12:27:33
【问题描述】:

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

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 时我得到了它

【问题讨论】:

  • 我认为关键是您只能获取 .png 文件
  • 哦,好的。谢谢。瓶子框架中有没有办法在不指定.png的情况下查找图像?还是我必须将其编码?

标签: python image static bottle


【解决方案1】:

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

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

【讨论】:

  • 如果您想使用子文件夹,请在您的路线上使用 :filename#.*# 或
猜你喜欢
  • 2012-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多