调用循环 html jinja 无法调用 table HTML 上的某些图像
Call loop html jinja does not work to call some images on table HTML
我想从 controller/static/foto
文件夹中调用一些图像显示在 table.html
上
当我使用 for loop
在 HTML 上使用 python 函数 img_dir
调用值照片时
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 张照片
文件夹路径中的文件夹内有 3 张照片 controller/static/foto
为什么还是空的?
Table 列照片似乎没有显示任何照片
注意: 在照片栏中,它只包含数据库中照片名称的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 结果时,它就像未调用的图像一样?
inspect the 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' ) }}">
当我这样做时,即使是“+image”也没有 space
second image inspect URL
直接复制到你的评论,得到jinja2.exception
got Jinja2.exception
directly copy source code
用路径变量测试,没有错误但不工作
you implement it like this?
if its work, there should be two picture each row
新检查路径变量
just delete {{ row 4 }} those space must be from unimplement code
请检查您发送的文件路径是否正确。
我认为你在文件路径中放置了两次静态路径。
<img src="{{ url_for('static', filename='controller/static/foto/' + image) }}">
这里的文件名参数'controller/static/'不应该存在,去掉它再试试。
我认为它会起作用。
所以这是因为有一个名为 table 的函数 return table.html 就像这样,这就是 img_dir 中的 return 函数不起作用的原因
the system taking priority of return function
解决方法是将它们合并为一个,所以return将它们合并为一个,没有一个优先。
merge the code as one return
他们调用的结果,但又出现了另一个问题,我猜可能需要新票
problem solved but its just beginning
我想从 controller/static/foto
文件夹中调用一些图像显示在 table.html
上
当我使用 for loop
img_dir
调用值照片时
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 张照片
文件夹路径中的文件夹内有 3 张照片 controller/static/foto
为什么还是空的?
Table 列照片似乎没有显示任何照片
注意: 在照片栏中,它只包含数据库中照片名称的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 结果时,它就像未调用的图像一样?
inspect the 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' ) }}">
当我这样做时,即使是“+image”也没有 space
second image inspect URL
直接复制到你的评论,得到jinja2.exception got Jinja2.exception
directly copy source code
用路径变量测试,没有错误但不工作
you implement it like this?
if its work, there should be two picture each row
新检查路径变量
just delete {{ row 4 }} those space must be from unimplement code
请检查您发送的文件路径是否正确。 我认为你在文件路径中放置了两次静态路径。
<img src="{{ url_for('static', filename='controller/static/foto/' + image) }}">
这里的文件名参数'controller/static/'不应该存在,去掉它再试试。
我认为它会起作用。
所以这是因为有一个名为 table 的函数 return table.html 就像这样,这就是 img_dir 中的 return 函数不起作用的原因
the system taking priority of return function
解决方法是将它们合并为一个,所以return将它们合并为一个,没有一个优先。
merge the code as one return
他们调用的结果,但又出现了另一个问题,我猜可能需要新票
problem solved but its just beginning