Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Proxy argument #2

merged 2 commits into from

2 participants


from the doc:

Improving load time on pages with many images
If you have just a few images on your page, the standard base URL should be fine. However, if you have many images, you can add a number 0-9 and a dot just before If you specify a different number for each image on your page, the browser will try to load more images simultaneously, rather than waiting to load them in sequence. However, you should only need this if you're loading perhaps five or more images on a page. For example:

Default to proxy = 0


Btw, I wrote some views to create batches of 100 QR codes, or to download a zip file containing those qr codes and text (which wasn't very easy to do).

If you see some interest in integrating them to the app, let me know.


@pablorecio pablorecio merged commit 5fc3e5e into pablorecio:master

Thank you! Seems really nice.

Sorry for not answering before, but I didn't get any GitHub notification...


my pleasure !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
@@ -31,15 +31,25 @@ Its usage is very simple. You just need to use the templatetag as follows:
- {% qr_from_text "text" "size" %}
+ {% qr_from_text "text" "size" "proxy" %}
- {% qr_from_mail "mail_address" "size" %}
+ {% qr_from_mail "mail_address" "size" "proxy" %}
+Example when looping on a list of QR codes to generate::
+ {% for qrcode in qrcode_list %}
+ {% cycle 0 1 2 3 4 5 6 7 8 9 as proxy silent %}
+ <p class="qrcodeImage">{% qr_from_text "text" "size" proxy %}
+ {% endfor %}
* Size is not mandatory, and defines the dimensions of the QR code as following: 's' (120x120 pixels), 'm' (230x230 pixels), 'l' (350x350) or an integer with the size that you want to give to the QR-code (like 40, 80 or 500). Any other option will be ignored and will use 'm' as default.
* qr_from_mail tag just add a simple "mailto:" at the beggining, because some qr scanners can detect that as an email address in order to send it an email.
+ * proxy is a number between 0 to 9. By calling different proxies for different qr codes, you will improve the load time on pages with many images (default to 0)
QR-code for contact information
@@ -52,12 +62,13 @@ Its usage is similiar to the basics:
- {% qr_from contact contact "size" %}
+ {% qr_from contact contact "size" "proxy" %}
- * Size is the same as previosly
+ * Size is the same as previously
* contact should be a Python dictionary (or any other hash structure) that could contain the following elements:
+ * proxy is the same as previously
* *name* - Complete name
* *phone_number*
@@ -85,12 +96,14 @@ Another templatetag can be used to render a QR-code that links to a Django objec
the previous templatetags, the usage is very simple:
- {% qr_from_object object "size" %}
+ {% qr_from_object object "size" "proxy" %}
- * Size is the same as previosly
+ * Size is the same as previously
* Object it's an instance of a Django model, that must implements the 'get_absolute_url' method in order to get the object's address.
+ * Proxy is the same as previously
Change service for QR generating
@@ -100,7 +113,7 @@ template *qrcode/qr_tag.html* contains the following:
-<img src="{{ size }}x{{ size }}&chl={{ text }}" />
+<img src="http://{{ proxy }}{{ size }}x{{ size }}&chl={{ text }}" />
But if you want to use some other service, like *qrserver*, you just need to add a new template in your templates dirs with
the following code:
2  qrcode/templates/qrcode/qr_tag.html
@@ -1 +1 @@
-<img src="{{ size }}x{{ size }}&chl={{ text }}" />
+<img src="http://{{ proxy }}{{ size }}x{{ size }}&chl={{ text }}" />
18 qrcode/templatetags/
@@ -21,7 +21,7 @@
@register.inclusion_tag('qrcode/qr_tag.html', takes_context=True)
-def qr_from_text(context, text, size='M'):
+def qr_from_text(context, text, size='M', proxy=0):
if type(size) == type(0) or type(size) == type('') and size.isdigit():
# this checks if it's an integer or a string with an integer
actual_size = size
@@ -30,17 +30,17 @@ def qr_from_text(context, text, size='M'):
if not size.lower() in sizes_dict:
size = 'm'
actual_size = sizes_dict[size.lower()]
- return {'text': text,
- 'size': actual_size}
+ return {'text': text, 'size': actual_size, 'proxy': proxy}
@register.inclusion_tag('qrcode/qr_tag.html', takes_context=True)
-def qr_from_mail(context, text, size='M'):
- return qr_from_text(context, text='mailto:%s' % text, size=size)
+def qr_from_mail(context, text, size='M', proxy=0):
+ return qr_from_text(context, text='mailto:%s' % text, size=size,
+ proxy=proxy)
@register.inclusion_tag('qrcode/qr_tag.html', takes_context=True)
-def qr_from_contact(context, contact, size='M'):
+def qr_from_contact(context, contact, size='M', proxy=0):
final_string = 'MECARD:'
if contact['name']:
final_string += 'N:%s;' % contact['name'].replace(' ', '+')
@@ -56,12 +56,12 @@ def qr_from_contact(context, contact, size='M'):
if contact['company']:
final_string += 'ORG:%s;' % contact['company'].replace(
' ', '+')
- return qr_from_text(context, text=final_string, size=size)
+ return qr_from_text(context, text=final_string, size=size, proxy=proxy)
@register.inclusion_tag('qrcode/qr_tag.html', takes_context=True)
-def qr_from_object(context, obj, size='M'):
+def qr_from_object(context, obj, size='M', proxy=0):
domain = Site.objects.get_current().domain
path = obj.get_absolute_url()
text = 'http://%s%s' % (domain, path)
- return qr_from_text(context, text, size=size)
+ return qr_from_text(context, text, size=size, proxy=proxy)
Something went wrong with that request. Please try again.