I am using Python PIL library in Django Rest Framework for building qr code and saving it to static directory.
def generate_qr(self, name):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_M,
box_size=15,
border=5
)
qr.add_data(name)
qr.make(fit=True)
img = qr.make_image(fill='black', back_color='white')
img.save(settings.STATIC_ROOT+"/asset-tags/name.png")
return(name+ '.png')
settings.py for media and static urls:
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_URL = "/mediafiles/"
MEDIA_ROOT = os.path.join(BASE_DIR, "mediafiles")
But while saving it throws an error saying /usr/app/static/name.png : no file or directory. I am creating new file so how can it find the image in given folder.
Any Help will be appreciated. Thanks.