Generate QR Code using Jinja

I have a custom print format that displays a qr code using {{ qrcode ( }}

from .custom_app.qrcode import jenvs
jenv = jenvs


import frappe
from frappe import _
import qrcode
import qrcode.image.svg
import io
import base64

jenvs = {
	"methods": [
	"filters": [],

def gen_qr(name):		
	img = qrcode.make(name)
	buffer = io.BytesIO()
	img_str = base64.b64encode(buffer.getvalue()).decode()
	return "data:image/png;base64, " + img_str

However, when I select the custom print format, it appears jinja2.exceptions.UndefinedError: ‘gen_qr’ is undefined

Am I doing something wrong? Do I need to whitelist it somewhere else?

It used to work on version 13, but I can’t make it work since I updated to version 14.

According to Migrating to Version 14 · frappe/frappe Wiki · GitHub jenv = { was replaced with jinja = { and “qrcode:custom_app.qrcode.gen_qr” was replaced with “custom_app.qrcode.gen_qr”. However, I still din’t manage to get it working

1 Like

Can you post all relevant lines in your file? It’s working fine for me.