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