Generating QR Codes with Django

Create your Django project or go with my github simple Django project already created:
https://github.com/38130/mysite 

  • Project named mysite
  • With an app named polls
  • some simple configurations for static and media 
  • a simple view, url and template for an index.html page

 

pip install qrcode

 

 

import qrcode
import base64
from io import BytesIO
from django.views.generic import TemplateView


class index(TemplateView):
    template_name = "polls/index.html"

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        texto = "https://www.jaimedcsilva.com"

        qr = qrcode.make(texto)
        buffer = BytesIO()
        qr.save(buffer, format="PNG")

        context["qr"] = base64.b64encode(buffer.getvalue()).decode()

        return context

 

 


...

<img src="data:image/png;base64,{{ qr }}">

 


Tested with Django==5.2


13 Feb. 2026 | Last Updated: 13 Feb. 2026 | jaimedcsilva

Related
  • Using ngrok with Django
  • Opening a Django project through a .exe file
  • Creating an online store with Django
  • CRUD
  • Creating a Basic Django Project Automatically
  • Filter Horizontal in a custom template
  • GeoIP tracking with IpInfo and Django
  • GeoIP tracking with MaxMind and Django
  • Django User Agents
  • Generating Temporary Download Links
  • Cython - Hiding the Code of a Django Project
  • Quick & Easy Django Deployment on PythonAnywhere
  • A Brief History of Django
  • Django & Paypal Webhooks
  • Generating QR Codes with Django

  • Buy Me a Coffee