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?
Advertisement
Answer
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