{% load qr_code %} Demo Site of django-qr-code {% block content %}

Django QR Code Demo Site

This is a demo site for the Django QR Code application.

Latest PyPI Version Documentation Status Build Status Coverage Status

Image Formats

The SVG is the default image format. It is a vector image format so it can be scaled as wanted. However, it has two drawbacks.

The size is not given in pixel, which can be problematic if the design of your website relies on a fixed width (in pixels).

The format is less compact than PNG and results in a larger HTML content. Note that a base64 PNG is less compressible than a SVG tag, so it might not matter that much of you use HTML compression on your web server.

SVG has broad support now and it will work properly on any modern web browser.

Examples of qr_from_text Usages

The qr_from_text tag renders an inline QR code within your Django template. It comes with several options to customize the image format (SVG or PNG), the size, the border and the matrix size.

A tiny "hello world" QR code in SVG format (default format)

A tiny "hello world" QR code in PNG format

A small "hello world" QR code

Template code:
{% templatetag openblock %} qr_from_text "Hello World!" size="T" image_format="svg" {% templatetag closeblock %} {% templatetag openblock %} qr_from_text "Hello World!" size="T" image_format="png" {% templatetag closeblock %} {% templatetag openblock %} qr_from_text "Hello World!" size="S" {% templatetag closeblock %}
{% qr_from_text "Hello World!" size="T" image_format="svg" %}
{% qr_from_text "Hello World!" size="T" image_format="png" %}
{% qr_from_text "Hello World!" size="S" %}


A medium "hello world" QR code (default size) with level H of error correction (up to 30% damage)

A large "hello world" QR code with level L of error correction (up to 7% damage)

A huge "hello world" QR code with level M of error correction (default level, up to 15% damage)

Template code:
{% templatetag openblock %} qr_from_text "Hello World!" size="M" error_correction="H" {% templatetag closeblock %} {% templatetag openblock %} qr_from_text "Hello World!" size="L" error_correction="L" {% templatetag closeblock %} {% templatetag openblock %} qr_from_text "Hello World!" size="H" error_correction="M" {% templatetag closeblock %}
{% qr_from_text "Hello World!" size="M" error_correction="H" %}
{% qr_from_text "Hello World!" size="L" error_correction="L" %}
{% qr_from_text "Hello World!" size="H" error_correction="M" %}


A custom "hello world" QR code with size 8 and version 12

A custom "hello world" QR code with size 10 and border 6

A custom "hello world" QR code using a QRCodeoptions instance. Here the QRCodeoptions instance has a size t, a border of 6 modules, and a level L of error correction (up to 7% damage).

Template code:
{% templatetag openblock %} qr_from_text "Hello World!" size=8 version=12 {% templatetag closeblock %} {% templatetag openblock %} qr_from_text "Hello World!" size=10 border=6 {% templatetag closeblock %} {% templatetag openblock %} qr_from_text "Hello World!" options=options_example {% templatetag closeblock %}
{% qr_from_text "Hello World!" size=8 version=12 %}
{% qr_from_text "Hello World!" size=10 border=6 %}
{% qr_from_text "Hello World!" options=options_example %}

Examples of qr_url_from_text Usages

The qr_url_from_text tag generates an url to an image representing the QR code. It comes with the same options as qr_from_text to customize the image format (SVG or PNG), the size, the border and the matrix size. It also has an additional option cache_enabled to disable caching of served image.

The image targeted by the generated URL is served by a view provided in qr_code.urls. Therefore you need to include the URLs provided by qr_code.urls in your app in order to make this tag work. This can be achieved with something like this:

from django.conf.urls import include, url from qr_code import urls as qr_code_urls urlpatterns = [ url(r'^qr_code/', include(qr_code_urls, namespace="qr_code")), ]

A medium "hello world" QR code that uses an URL to serve the image in SVG format

A "hello world" QR code in version 10 that uses an URL to serve the image in PNG format

A "hello world" QR code in version 20 that uses an URL to serve the image in SVG format, and disable caching for served image

Template code:
<img src="{% templatetag openblock %} qr_url_from_text "Hello World!" {% templatetag closeblock %}" alt="Hello World!"> <img src="{% templatetag openblock %} qr_url_from_text "Hello World!" size=8 version=10 image_format='png' {% templatetag closeblock %}" alt="Hello World!"> <img src="{% templatetag openblock %} qr_url_from_text "Hello World!" size=8 version=20 cache_enabled=False {% templatetag closeblock %}" alt="Hello World!">
Hello World!
Hello World!
Hello World!

QR Codes for Applications

Aside from generating a QR code from a given text, you can also generate codes for specific application purposes, that a reader can interpret as an action to take: open a mail client to send an email to a given address, add a contact to your phone book, connect to a Wi-Fi, start a SMS, etc. See this documentation about what a QR code can encode.

Django QR Code proposes several utility tags to ease the generation of such codes, without having to build the appropriate text representation for each action you need. This remove the hassle of reading the specifications and handling all the required escaping for reserved chars.

Please note that some commands are common patterns, rather than formal specifications. Therefore, there is no guarantee that all QR code readers will handle them properly.

Start an email

Template code:
{% templatetag openblock %} qr_for_email "john.doe@domain.com" {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_email "john.doe@domain.com" {% templatetag closeblock %}"
{% qr_for_email 'john.doe@domain.com' %}

Compose a phone number

Template code:
{% templatetag openblock %} qr_for_tel "+41769998877" {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_tel "+41769998877" {% templatetag closeblock %}"
{% qr_for_tel '+41769998877' %}

Start a SMS

Template code:
{% templatetag openblock %} qr_for_sms "+41769998877" {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_sms "+41769998877" {% templatetag closeblock %}"
{% qr_for_sms '+41769998877' %}

Display a geolocation on default map app

Template code:
{% templatetag openblock %} qr_for_geolocation latitude=586000.32 longitude=250954.19 altitude=500 {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_geolocation latitude=586000.32 longitude=250954.19 altitude=500 {% templatetag closeblock %}"
{% qr_for_geolocation latitude=586000.32 longitude=250954.19 altitude=500 %}
Template code:
{% templatetag openblock %} qr_for_geolocation coordinates=geolocation_coordinates {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_geolocation coordinates=geolocation_coordinates {% templatetag closeblock %}"
{% qr_for_geolocation coordinates=geolocation_coordinates %}

Display a geolocation on Google Maps

Template code:
{% templatetag openblock %} qr_for_google_maps latitude=586000.32 longitude=250954.19 {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_google_maps latitude=586000.32 longitude=250954.19 {% templatetag closeblock %}"
{% qr_for_google_maps latitude=586000.32 longitude=250954.19 %}
Template code:
{% templatetag openblock %} qr_for_google_maps coordinates=google_maps_coordinates {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_google_maps coordinates=google_maps_coordinates {% templatetag closeblock %}"
{% qr_for_google_maps coordinates=google_maps_coordinates %}

Configure Wi-Fi connexion

Template code:
{% templatetag openblock %} qr_for_wifi wifi_config {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_wifi wifi_config {% templatetag closeblock %}"
{% qr_for_wifi wifi_config %}
Template code:
{% templatetag openblock %} qr_for_wifi wifi_config=wifi_config {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_wifi wifi_config=wifi_config {% templatetag closeblock %}"
{% qr_for_wifi wifi_config=wifi_config %}
Template code:
{% templatetag openblock %} qr_for_wifi wifi_config options=options_example {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_wifi wifi_config options=options_example {% templatetag closeblock %}"
{% qr_for_wifi wifi_config options=options_example %}

Add contact to phone book

Template code:
{% templatetag openblock %} qr_for_contact contact_detail {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_contact contact_detail {% templatetag closeblock %}"
{% qr_for_contact contact_detail %}
Template code:
{% templatetag openblock %} qr_for_contact contact_detail=contact_detail {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_contact contact_detail=contact_detail {% templatetag closeblock %}"
{% qr_for_contact contact_detail=contact_detail %}

Watch a YouTube video

Template code:
{% templatetag openblock %} qr_for_youtube 'J9go2nj6b3M' {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_youtube 'J9go2nj6b3M' {% templatetag closeblock %}"
{% qr_for_youtube 'J9go2nj6b3M' %}
Template code:
{% templatetag openblock %} qr_for_youtube video_id {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_youtube video_id {% templatetag closeblock %}"
{% qr_for_youtube video_id %}

Open a Google Play app page

Template code:
{% templatetag openblock %} qr_for_google_play 'ch.admin.meteoswiss' {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_google_play 'ch.admin.meteoswiss' {% templatetag closeblock %}"
{% qr_for_google_play 'ch.admin.meteoswiss' %}
Template code:
{% templatetag openblock %} qr_for_google_play 'ch.admin.meteoswiss' options=options_example {% templatetag closeblock %} <img src="{% templatetag openblock %} qr_url_for_google_play 'ch.admin.meteoswiss' options=options_example {% templatetag closeblock %}"
{% qr_for_google_play 'ch.admin.meteoswiss' options=options_example %}
{% endblock %}