模块"qrcode"没有属性"make" [英] module 'qrcode' has no attribute 'make'

查看:24
本文介绍了模块"qrcode"没有属性"make"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将python库qrcode == 6.1与django == 3.1.2集成时.我一直在尝试生成一个qrcode,其中将包含我其他网站的URL链接.

While integrating python library qrcode==6.1 with django==3.1.2. I have been trying to generate a qrcode which will contain the URL links for my other websites.

Models.py

Models.py

from django.db import models
import qrcode
from io import BytesIO
from django.core.files import File
from PIL import Image, ImageDraw

# Create your models here.

class Website(models.Model):
    name = models.CharField(max_length=200)
    qr_code = models.ImageField(upload_to='qr_codes', blank=True)

    def __str__(self):
        return str(self.name)
    
    def save(self, *args, **kwargs):
        qrcode_img = qrcode.make(self.name)
        canvas = Image.new('RGB', (290,290), 'white')
        draw = ImageDraw.Draw(canvas)
        canvas.paste(qrcode_img)
        fname = f'qr_code_{self.name}.png'
        buffer = BytesIO()
        canvas.save(buffer,'PNG')
        self.qr_code.save(fname, File(buffer), save=False)
        canvas.close()
        super().save(*args, **kwargs)

但是它总是显示一个错误,指出模块'qrcode'不包含任何名为'make()'的属性.我想知道如何解决这个问题?

But It always display an error saying that module 'qrcode' doesnot contain any attribute named 'make()'. I want to know how to resolve this?

推荐答案

确保在 models.py 所在的目录中没有任何名为 qrcode.py 的文件.找到.

Make sure there are not any files named qrcode.py in the directory where models.py is located.

有关更多信息,请检查 https://github.com/lincolnloop/python-qrcode/issues/185

For more information check https://github.com/lincolnloop/python-qrcode/issues/185

这篇关于模块"qrcode"没有属性"make"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆