module 'qrcode' has no attribute 'make'

≯℡__Kan透↙ 提交于 2021-01-29 07:27:10

问题


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

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)

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


回答1:


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

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



来源:https://stackoverflow.com/questions/64314649/module-qrcode-has-no-attribute-make

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!