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. Django Settings Assignment Expressions aka Walrus Operator example by webology 2 weeks, 5 days ago
  2. codigo alto nivel by MrRocklion 2 months, 2 weeks ago
  3. Load template from specific app by Krzysiek555 3 months, 1 week ago
  4. PostgreSQL JSON subqueries by dolamroth 3 months, 1 week ago
  5. "Magic Link" Management Command by webology 8 months, 1 week ago

Comments

Please login first before commenting.