Django应用程序,提供生成二维码的简单模板标记
django-qrcode的Python项目详细描述
内容
Django QR
Information
django qr是一个简单的django应用程序,它提供了一些模板标记 它允许在django站点上自动包含qr码。
Usage
它的用法很简单。您只需按如下方式使用templateTag即可:
{% load qr_tags %} ... {% qr_from_text "text" "size" %} or {% qr_from_mail "mail_address" "size" %}
其中:
- 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.
QR-code for contact information
还有一个模板标签,用来呈现二维码,允许存储 一些联系信息,如姓名、电话号码、电子邮件地址或 我们公司的名字。
它的用法与基本用法类似:
{% qr_from contact contact "size" %}
其中:
- Size is the same as previosly
- contact should be a Python dictionary (or any other hash structure) that could contain the following elements:
- name - Complete name
- phone_number
- url - some url address, your blog or personal webpage
- company
例如,您可以创建如下联系人词典:
contact = { 'name': 'Pablo Recio', 'phone_number': '00000000', 'email': 'foo@example.com', 'url': 'http://www.zocolab.es', 'company': 'Zocolab', }
QR-code of Django object URL
另一个templatetag可用于呈现链接到django对象url的qr代码。作为 前面的模板标记,用法非常简单:
- ::
- {%qr_from_object object“size”%}
其中:
- Size is the same as previosly
- 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.
Change service for QR generating
默认情况下,django qr使用google chart生成二维码。但是这个可以用新的模板来改变。违约 模板qrcode/qr_tag.html包含以下内容:
<img src="http://chart.apis.google.com/chart?cht=qr&chs={{ size }}x{{ size }}&chl={{ text }}" />
但是如果你想使用其他服务,比如qrserver,你只需要在模板目录中添加一个新的模板 以下代码:
<img src="http://api.qrserver.com/v1/create-qr-code/?size={{ size }}x{{ size }}&data={{ text }}" />
其思想是,qrcode/qru tag.html包含一个img标记和对所需服务的调用,它包含 变量size和data。