我现在想用pybarcode在网页上输出条形码,由于需要临时存储barcode生成的图片文件,于是引用了 cStringIO的包,来做,我写了部分代码如下:
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
def generateBarcode(request,id):
TESTPATH = os.path.join(BASE_DIR,'temp')
tempfile.tempdir = 'temp'
temp_img = tempfile.TemporaryFile()
temp_img = StringIO()
code = barcode.Code39(id,add_checksum=False,writer=ImageWriter())
filename = code.save(os.path.join(TESTPATH,id))
现在不知道如何结合cStringIO来输出临时文件到网页上,还请前辈指点。
我看了github的这篇文章,还是不会
https://github.com/mozillazg/pyqr/commit/8273a2910f9f049d20ad21d904f10e386f120662#diff-5bc02cefb3ea9e27f1a6776eabd1935dR193