我有一个金字塔视图,需要生成一个二维码并将其作为图像返回给用户。我想避免存储图像,我只想生成它,发送它,然后忘掉它。在
我做的第一件事是这样的:
oRet = StringIO.StringIO()
oQR = pyqrcode.create('yo mamma')
oQR.svg(oRet, scale=8)
return Response(body = oRet.read(), content_type="image/svg")
但这会生成一个无法打开的svg文件。在
再近一点看:
^{pr2}$所以我的问题是:如何将新生成的二维码作为金字塔响应返回,而不将其存储在磁盘上?我不太在意图像的格式
这是我的代码:
我们有一个赢家:
诀窍是用
oRet.getvalue()
代替oRet.read()
相关问题 更多 >
编程相关推荐