def getQRCode(request, music_id):
# generate token - save to database
# generate URL with token --> this will be a QR code to be displayed
newMusic = Music.objects.get(id=music_id)
stringToHash = str(time.time()) + str(newMusic.artist) + str(newMusic.title)
h = hashlib.sha1()
h.update(stringToHash)
tokenToAppendinURL = str(h.hexdigest())
# save music query to database
newQuery = MusicQuery(query=newMusic, token=tokenToAppendinURL)
newQuery.save()
#QR code to be displayed
# url = pyqrcode.create('http://35.163.220.222:8000/musician/music/' + tokenToAppendinURL)
# url = pyqrcode.create('http://54.209.248.145:8000/musician/music/' + tokenToAppendinURL)
# url = pyqrcode.create('http://localhost:8000/musician/music/' + tokenToAppendinURL)
url = pyqrcode.create(settings.ROOT_URL + '/musician/music/' + tokenToAppendinURL)
# image_as_str = code.png_as_base64_str(scale=5)
# html_img = '<img src="data:image/png;base64,{}">'.format(image_as_str)
strToSave = 'musician/static/images/' + tokenToAppendinURL + '.png'
url.png(strToSave, scale=6)
strToShow = '/static/images/' + tokenToAppendinURL + '.png'
x = json.dumps({'qrpath': strToShow})
return JsonResponse(x, safe=False)
# executed on QR code url
评论列表
文章目录