my use case is:
I generate in some view with certain url qrcode, and then I use it in template like this:
<img src="/qrcode/2">
I know holder.js and I would like to display something like:
<img src="holder.js/200x200/text:qrcode not avaliable">
when the qrcode image is not loaded becasue of anything (like bad id, soem crash of PIL library...).
What will be the most clean solution?
I was trying in view:
return HttpResponse("holder.js/200x200/text:qrcode not avaliable", content_type="image/png")
also with mime type set to text, but it is not replacing the source src in img tag.
UPDATE:
I think for a while, and I started being afraid, that I am trying to reinvent the wheel... So I decided to pass appropriate url in view rendering the page:
def certificate(request, pk):
try:
spot = Spot.objects.get(pk=pk)
if request.method == 'GET':
link = '/qrcode/%d' % int(pk)
return render(
request,
'certificate.html',
{'spot': spot, 'qrcode_link': link})
except:
return render(
request,
'certificate.html',
{'spot': None,
'qrcode_link': 'holder.js/200x200/text:qrcode not avaliable'})
And in template I just: <img src="{{qrcode_link}}">
But the question is still open and all ideas, how to do it better will be apriciated:-)