Login

Filter to generate QR codes

Author:
javinievas
Posted:
July 30, 2010
Language:
Python
Version:
Not specified
Score:
1 (after 1 ratings)

You can convert any string to a QR code image as easy as use a simple filter, thanks to google charts api.

Common use: <img src="{{object.attribute_to_encode|qr:"120x130"}}" />

This will create a 120(width) x 130(heiht) image with the value of the attribute_to_encode encoded in a QR coded image.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from django import template

register = template.Library()

@register.filter
def qr(value,size="150x150"):
    """
        Usage:
        <img src="{{object.code|qr:"120x130"}}" />
    """
    return "http://chart.apis.google.com/chart?chs=%s&cht=qr&chl=%s&choe=UTF-8&chld=H|0" % (size, value)

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 3 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 3 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 10 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 11 months ago
  5. Help text hyperlinks by sa2812 11 months, 3 weeks ago

Comments

Please login first before commenting.