python - 图像不匹配 pil,django 模型
问题描述
我正在尝试在我的 Django 模型中创建一个 QR 码,它会在保存新记录时自行创建。问题是,在我的开发环境中进行测试时,一切都很好,但在生产中,我在下面的指定行上收到错误消息:ValueError,图像不匹配。
from django.core.files import File
import qrcode
from io import BytesIO
from PIL import Image
from datetime import date
# this is the save method of the django model class, I just left out the other methods
def save(self, *args, **kwargs):
img = qrcode.make(self.account_id)
canvas = Image.new('RGB', (400, 400), 'white')
canvas.paste(img) # Error occurs on this line
buffer = BytesIO()
canvas.save(buffer, 'PNG')
canvas.close()
fname = f'pdf-qr-code-{self.account_id}.png'
self.menu_qr_code.save(fname, File(buffer), save=False)
super(PDFMenu, self).save(*args, **kwargs)
我不知道问题是否出在我的 ubuntu 服务器上的配置上,因为这是问题发生的地方,但可能需要一种在此自定义保存方法中创建二维码的新方法。
在此先感谢您的帮助。
解决方案
推荐阅读
- android - Android应用程序,重命名后应用程序不断停止错误
- safari - 支付请求 API - Safari 上的基本卡
- sql-server - 删除前导和尾随逗号
- javascript - 远程 preventDefault() 另一个函数中的表单
- excel - excel中将多个单元格与随机值进行比较并返回条件输出的公式
- php - 在服务提供者中合并到请求的参数在服务提供者之外丢失 - Laravel 5.6
- r - 运行 GEE 后,系数表不显示两个自变量的结果
- apache - 致命错误无法分配 134217728 字节的共享内存段:mmap:无法分配内存 (12)
- firebase - Firestore 侦听器的异常
- java - 改进我的键盘输入 (KeyListener) Java