En la vista definimos el codigo que crea y serializa el codigo QR
y luego regresa la respuesta.
from django.http import HttpResponse
import qrcode
def return_qr(request):
qr = qrcode.make('hola')
# serialize to HTTP response
response = HttpResponse(content_type="image/png")
qr.save(response, "PNG")
return response
Luego agregamos la ruta en urls.py de la app
#url de la app urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('sign/', views.sign, name='sign'),
path('return_qr',views.return_qr, name='return_qr')
]
y por ultimo en el template llamamos al metodo de la vista.
<img src='{% url "return_qr" %}' />
http://effbot.org/zone/django-pil.htm
https://pypi.python.org/pypi/qrcode
No hay comentarios:
Publicar un comentario