How do I create a QR code in Python without saving it as an image

I am trying to make Qr Codes using Python on a Django applicaiton using this code :

def generate_qr_code (reference):
    qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_H,
    box_size=10,
    border=4,
    )
    qr.add_data(reference)
    qr.make(fit=True)
    img = qr.make_image(fill_color="black", back_color="white").convert('RGB')
    filename = reference+".jpeg"
    img.save("C:\\qrs\\"+filename)

Now, this function is called when I click on a "Generate Qr Code" Button. My problem is that I would like the Qr Code to be displayed on a new tab on my browser instead of it being saved as an image, as I only need to print them on paper at that moment and I have no need to keep the images.

Thank you for your help.

convert the image to base64 and show it in your html like this

import base64
b64 = base64.b64encode(image).decode("utf-8")

After all, I managed to do so by using this simple line in my HTML:

<img id='barcode' src="https://api.qrserver.com/v1/create-qr-code/?data={{ref}}" alt="" title="{{ref}}" width="150" height="150"/>
Back to Top