Filter to generate QR codes

 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. Generate QR Code image for a string by johnnoone 4 years ago
  2. Auto Generate/Save Thumbnails using Template Filter (scale max_x, max_y, or both) by ThisbeTom 4 years, 5 months ago
  3. [UPDATE]Filter to resize a ImageField on demand by rafacdb 4 years, 9 months ago
  4. Filter to resize a ImageField on demand by michelts 6 years, 1 month ago
  5. Letterbox for sorl-thumbnail by Mogga 4 years, 1 month ago

Comments

robvdl (on August 12, 2011):

It looks like this filter will break using characters that cannot be put directly in the url, that is spaces, &, =, + and newlines for multiline strings.

snippet #1494

That snippet uses urllib.urlencode to get around this, however that snippet is also fixed to a 150x150 size.

#

(Forgotten your password?)