python - 在幻灯片烧瓶中显示的磁环
问题描述
我正在尝试制作一个循环以在烧瓶中的幻灯片中显示图像,但我想获取放置图像名称的图像,我正在尝试使用 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>
解决方案
您正在导入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"))
推荐阅读
- multithreading - 使用 Threads.@threads 运行 ccall 时出现分段错误
- docker - 将 Docker 映像从 GKE 中运行的容器推送到 Google Container Registry
- php - Coinbase API 发送货币交易哈希
- c++ - 原始 yuv420p 数据上的 sws_scale
- primefaces - 在使用 primefaces 的 on 按钮中进行选择时更新 p:datalist
- node.js - env2 找不到 .env 文件
- javascript - Discord.js 以任何方式获取所有角色
- css - 输入框内的文本太靠近边框
- python-3.6 - 如何将简单的树视图下载到 pdf 中,因为我没有任何 one2many 字段可以使用 foreach 标记进行循环
- javascript - 如何在html中一键单击重定向两个页面?