DEV Community

Michael Learns
Michael Learns

Posted on

QR Code Generator with Django

Hi devs! I'm wondering how you would generate your own QR code and add them over to your Django app? I've seen and tried different QR code generator but all of them only supports PDF, Images, Urls, and etc. I'm looking to generate a QR code of an object.

Not getting it? 🤔

It's like there's a QR code and then it returns to me an object like so:
{name: ' on', age: null, job: 'Developer'}

That way I can like open a dialog and just input the data to the input value or something.

By the way I'm using this on a React-Native app. 😁

Thanks!

Top comments (4)

Collapse
 
taigrr profile image
Tai Groot • Edited

Well, as far as I can see this is a security risk no matter how you do it, unless you restrict the feature to dev environments.

If it's for dev only, then you should probably be fine using eval etc.

What I would do is use the python qrcode module, and pass it the object (in json format) as a string. On the other end, get that string output from the qr decoder and run json.load to get your object.

Collapse
 
imronlearning profile image
Michael Learns

Is that so? Why is it a security risk?

Collapse
 
taigrr profile image
Tai Groot

It could potentially be used for arbitrary code execution.

stackoverflow.com/questions/643439...

I suppose if you very strictly check your JSON first you might be fine, so maybe I should revise "no matter how you do it" to "unless you're very careful."

Thread Thread
 
imronlearning profile image
Michael Learns

Ahh. Gotcha. So I'll need to strictly check the JSON if I'm going to implement QR code with json.