我想从controller/static/foto
文件夹调用一些图像在table.html
上显示
当我使用for loop
在HTML上使用python函数img_dir
调用value foto时
info/views.py
import controller import create app
import os
@info_blue.route('/img_dir')
def img_dir():
app = create_app('dev')
images = os.listdir('controller/static/foto')
return render_template("table.html", foto=images)
table.html
{% for row in value %}
<tr>
<td>{{row[0]}}</td>
<td>{{row[1]}}</td>
<td>{{row[2]}}</td>
<td>{{row[3]}}</td>
<td>
{% for image in foto %}
<img src="{{ url_for('static', filename='controller/static/foto/' + image) }}">
{% endfor %}
</td>
{% endfor %}
</tr>
它似乎不起作用,但当我试图用print(images)
检查文件夹的内容时,我检查有3张照片
文件夹路径controller/static/foto
中文件夹内的3张照片
为什么它还是空的
foto列上的表格似乎没有显示任何照片
注意:在foto列中,它只包含数据库中照片名称的varchar,仅用于指示照片显示时是否为正确的照片
这是文件夹路径
试图从foto/
调用单个映像
{% for row in value %}
<tr>
<td>{{row[0]}}</td>
<td>{{row[1]}}</td>
<td>{{row[2]}}</td>
<td>{{row[3]}}</td>
<td>
{% for image in foto %}
<img src="{{ url_for('static', filename='controller/static/foto/' + image) }}">
{% endfor %}
<img src="{{ url_for('static', filename='foto/18_Aug_2021|02:33.jpg' + image) }}">
</td>
{% endfor %}
</tr>
它可以工作,但只能在图像循环之外
在行循环内调用单个图像,但在图像循环外调用
当我尝试检查URL时,这是结果,就像没有调用图像一样
{% for image in foto %}
<img src="{{ url_for('static', filename='foto/'+image) }}">
{% endfor %}
<img src="{{ url_for('static', filename='foto/18_Aug_2021|02:33.jpg' ) }}">
当我这样做时,即使是“+图像”也没有空间
直接复制到您的评论并获得jinja2.exception got Jinja2.exception
使用path变量进行测试,无错误但不工作
if its work, there should be two picture each row
路径变量的新检查
just delete {{ row 4 }} those space must be from unimplement code
这是因为有一个名为table的函数,它像这样返回table.html,这就是为什么img_dir的返回函数不起作用的原因
the system taking priority of return function
解决方案是将它们作为一个id合并,因此返回将作为一个id合并,没有人拥有优先权
merge the code as one return
结果他们打电话来了,但又发生了另一个问题,我想可能要买新票了
problem solved but its just beginning
请检查您发送的文件路径是否正确。 我认为您已经在文件路径中放置了两次静态路径
此处文件名参数“controller/static/”不应存在,请将其删除并重试
我想它会起作用的
相关问题 更多 >
编程相关推荐