亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

flask - <img src如何指向并一個(gè)mongodb 的圖片字段?
怪我咯
怪我咯 2017-04-22 08:58:52
0
3
866

flask+mongoengine做一小站,model中使用FileField字段類型存儲(chǔ)上傳的圖片到文檔,該文檔記錄其它文本字段已經(jīng)以{{ xx.字段 }}的形式顯示在html模板頁(yè)中,圖片該怎么顯示呢?

img src={{ xx.圖片字段 }}...>肯定不行,源碼顯示為:<GridFSProxy:%20018560.jpg> .net中的基本思路是建一個(gè)一般處理程序頁(yè),將流輸出為圖片,再作為src屬性,flask或Python中沒(méi)寫(xiě)過(guò),有誰(shuí)能指點(diǎn)一下?

怪我咯
怪我咯

走同樣的路,發(fā)現(xiàn)不同的人生

reply all(3)
迷茫

Another way to solve the problem is: through src="/img/{{xx.image field.grid_id}}/" Defined as a public View Get the actual image stored through GridFS through the passed string objectid and output

from flask import Response
from bson.objectid import ObjectId
from mongoengine import *
app.route('/img/<oid>/')
def get_img(oid=None):
    if oid:
        proxy = GridFSProxy(grid_id=ObjectId(oid))
        return Response(proxy.read(),mimetype='image/jpeg')
迷茫

nginx+mongodbgridfs plug-in. No?

小葫蘆
 <img src="data:image/jpeg;base64,{{xx.圖片字段base64編碼}}" />

Similarly applies to other encodings and formats, but note that older browsers do not support this method.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template