我使用 python-qrcode 和 reportlab,我想生成一个 qrcode 并显示它而不将其保存为图像。
def member_card(request):
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="carte-membre.pdf"'
p = canvas.Canvas(response)
customer = request.user.customer
p.drawImage('./static/skin/img/carte-membre/carte-membre.jpg', 0, 530)
p.drawString(15, 720, customer.first_name + " " + customer.last_name)
p.drawString(15, 700, "Identifiant: " + customer.zipcode[:2] + " " + unicode(customer.id))
qr = qrcode.make(customer.first_name + "+" + customer.last_name + "+" + customer.zipcode[:2] + "+" + unicode(customer.id))
p.drawImage(qr , 170, 690, 70, 60)
p.showPage()
p.save()
return response
我有这个错误:
Traceback (most recent call last):
File "c:\Python27\lib\site-packages\django\core\handlers\base.py", line 115, i
n get_response
response = callback(request, *callback_args, **callback_kwargs)
File "c:\Users\Jeremy\Desktop\Izicap\django\izicap\customer\views.py", line 45
, in member_card
p.drawImage(qr , 170, 690, 70, 60)
File "c:\Python27\lib\site-packages\reportlab\pdfgen\canvas.py", line 926, in
drawImage
imgObj = pdfdoc.PDFImageXObject(name, image, mask=mask)
File "c:\Python27\lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 2123, i
n __init__
ext = string.lower(os.path.splitext(source)[1])
File "c:\Python27\lib\ntpath.py", line 190, in splitext
return genericpath._splitext(p, sep, altsep, extsep)
File "c:\Python27\lib\genericpath.py", line 91, in _splitext
sepIndex = p.rfind(sep)
AttributeError: 'bool' object has no attribute 'rfind'
谢谢