0

在我看来,我的 index.html 的代码是:

    <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
        <strong><h1>FlowTow</h1></strong>
        <b><h3>POWERED BY BOOTSTRAP</h3></b>
    </div>

    <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
        % for item in result:
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 image">

            <p class="username">{{item['user']}}</p>
            <p class="dates">{{item['timestamp']}}</p>
            <div class="clearfix"></div>
            <img src="static/images/{{item['filename']}}" alt="{{item['filename']}}" class="img-responsive imagee">

            <p class="likes">{{ item['likes'] }}Likes</p>

            <form action="/like" method="post" class="like_form">
                <input type="hidden" name="filename" value="{{item['filename']}}">
                <input type="submit" class="btn btn-success" value="Like">
            </form>
            <div class="clearfix"></div>
        </div>
        % end

    </div>

</div>

但索引不显示图像。图像存储在我的文件“静态/图像”中。当我检查网站的元素时,图像的地址显示如下:

<img src="static/images/cycling.jpg" alt="cycling.jpg" class="img-responsive imagee">

我确定图片的网址是正确的。谁能告诉我为什么没有显示图像?

4

1 回答 1

1

文档显示了如何提供静态文件:
只需在您的应用程序中为其创建一个路由并使用static_file()函数

from bottle import static_file
@route('/static/<filepath:path>')
def server_static(filepath):
    return static_file(filepath, root='/path/to/your/static/files')
于 2016-04-29T08:24:56.027 回答