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