Send QR Code in Email — Django

Md Mahmudul Huq Topu
2 min readAug 28, 2023

--

This is a very short tutorial on sending mails with QR code. Probable use case can be “Registration Ticket Verification by QR Scanning”. We will use django to send email with QR code.

Send QR Code in Email — Django

First you need to install some dependencies such as

pip install qrcode[pil]

Here we can pass any data for example pass ticket verification link or any secret code etc as qr_data. We could have saved the image in disk and then in DB and then pass the link but sometimes it may not work well. So in memory buffer the QR is generated on the fly and converted into a BASE64 image which we can easliy display on browser.

Now in qr.html you can design as per your requirements but to display the image just put this

<h3>Dear {{ name }}</h3>
<div style="text-align: center;">
<img src="data:image/png;base64,{{ qr_code_image }}" alt="QR Code">
</div>

So now just run the function (sendEmailQRCode) using shell or management command and see the results

Example Email Received in Inbox

--

--

Md Mahmudul Huq Topu

I’m a Full Stack Software Engineer at Skill Jobs.Also do youtubing(Metacentric Bangladesh) since 2014.