小编Mou*_*ima的帖子

如何在Python中创建二维码而不将其另存为图像?

我正在尝试使用以下代码在 Django 应用程序上使用 Python 制作二维码:

def generate_qr_code (reference):
    qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_H,
    box_size=10,
    border=4,
    )
    qr.add_data(reference)
    qr.make(fit=True)
    img = qr.make_image(fill_color="black", back_color="white").convert('RGB')
    filename = reference+".jpeg"
    img.save("C:\\qrs\\"+filename)
Run Code Online (Sandbox Code Playgroud)

现在,当我单击“生成二维码”按钮时,将调用此函数。我的问题是,我希望二维码显示在浏览器的新选项卡上,而不是将其保存为图像,因为当时我只需要将它们打印在纸上,不需要保留图像。

感谢您的帮助。

python django qr-code django-templates django-apps

2
推荐指数
1
解决办法
3878
查看次数

标签 统计

django ×1

django-apps ×1

django-templates ×1

python ×1

qr-code ×1