【问题标题】:Bottle (python) How to display a picture inside a template瓶子(python)如何在模板内显示图片
【发布时间】:2015-02-21 18:28:17
【问题描述】:

我需要一个非常简单的例子来理解pdf教程中的理论。

我尝试了不同的方法,但我总是得到一个符号,表示缺少图片文件。

文字显示正确。

你能给我正确的树状结构、文件位置和在一个非常基本的模板中显示图片的代码吗?

【问题讨论】:

    标签: python image templates bottle


    【解决方案1】:
    def show_pic():
        picture_name = 'my_picture.png'
        return template('template', picture=picture_name)
    

    在模板中:

    <img src="path/to/picture/{{picture}}">
    

    不要忘记允许您的应用从您的图片所在目录提供静态文件:

    @route('/path/to/picture/<picture>')
    def serve_pictures(picture):
        return static_file(picture, root='path/to/picture')
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    相关资源
    最近更新 更多