首页 > 解决方案 > 在幻灯片烧瓶中显示的磁环

问题描述

我正在尝试制作一个循环以在烧瓶中的幻灯片中显示图像,但我想获取放置图像名称的图像,我正在尝试使用 glob 但这会产生以下错误:TypeError: 'module' object is not callable

蟒蛇代码

    from flask import Flask, render_template
import glob
import os.path


app = Flask(__name__)



@app.route('/', methods=['GET', 'POST'])
def home():

    ruta_imagenes = glob(os.path.join(app.static_folder, "img"))
    render_template('index.html',ruta_imagenes=ruta_imagenes ) 





if __name__ == ('__main__'):
    app.run(debug=True)

HTML

<div class="carousel-inner">
    {% for _, ruta in enumerate(rutas_imagenes)  %}
    <div class="carousel-item ">
            {% if _ == 0 %}active{% endif %}
        <img src="{{ ruta }}" class="d-block w-100" alt="...">
    </div>
    {% endfor %}
</div>

标签: pythonhtmlflask

解决方案


您正在导入glob,然后只是调用它。但是glob是一个模块。

你想要的是要么

import glob
glob.glob(os.path.join(app.static_folder, "img"))

或者

from glob import glob
glob(os.path.join(app.static_folder, "img"))

推荐阅读