这段代码使用MyDB中的值呈现html模板
displayrows = db.execute("SELECT * FROM profiles WHERE profile_id = :profile_id", (session["user_id"],))
displayrows = db.fetchall()
displaycount = db.execute("SELECT COUNT(*) FROM bucketlist WHERE wish_id = :wish_id", (session["user_id"],))
for i in displayrows:
bytes_io = BytesIO(i[5])
for i in displaycount:
return render_template("profile.html", rows = displayrows, count = i[0], image = bytes_io)
这是呈现值的html页面的一部分
<div class="card bg-dark" style="width: 18rem;">
<p class="list-group-item">BucketList Size - {{ count }}</p>
{%for row in rows%}
<ul class="list-group list-group-flush">
<li class="list-group-item">Location - {{ row[1] }}, {{row[2]}}</li>
<li class="list-group-item">Looking for - {{row[3] }}</li>
<li class="list-group-item">Bio - {{row[4]}}</li>
</ul>
{%endfor%}
<img src="{{image}}" />
</div>
一般来说,我对python、flask和编码非常陌生,因此如果有人愿意花时间解释我如何在html页面上成功显示blob列中的数据,我将不胜感激。提前谢谢
以下是几点观察:
我想我是在假设你在这里要做什么,但希望这是有意义的
具有一个呈现配置文件页面的路由:
然后在模板
profile.html
中,在for循环中使用flask的url_for
函数生成指向图像的链接,将row[0]
(应该是该配置文件的id)作为ident
参数传递:该
url_for
函数将为下一个路由输出正确的超链接。请注意,这是如何接受作为概要文件id的ident
。您需要将your_blob_col
替换为包含bolb的列标题:因此
<img>
标记中的超链接将呈现为类似/i/123
的内容,当由profile_image
函数处理时,它将返回图像数据您可以在浏览器的开发工具(网络选项卡)中检查这些请求,以便更好地了解正在发生的事情。如果您的
profile
函数取而代之的是拉取n
配置文件,那么您将看到对profile
路由的1个请求,以及对profile_image
路由的n
请求如果有任何不清楚的地方,请告诉我:)
相关问题 更多 >
编程相关推荐