Django应用程序,提供生成二维码的简单模板标记

django-qrcode的Python项目详细描述


Django QR

Information

django qr是一个简单的django应用程序,它提供了一些模板标记 它允许在django站点上自动包含qr码。

Installation

从pypi安装后,只需将其添加到设置中 “qrcode”:

INSTALLED_APPS = (..., 'qrcode', ...)

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
  • email
  • 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标记和对所需服务的调用,它包含 变量sizedata

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
内部嵌套滚动视图的java Recyclerview?   返回空值的java MapPartitionFunction   java无法访问apache模块源代码中的系统定义的环境变量   java需要帮助确定用户输入的最大值和最小值   java检查文件是否存在,如果存在,则创建一个编号更高的新文件   针对许多不正确XML文档的XSD的XML验证在Java中不报告任何错误?   java有没有一种方法可以将json字符串甚至JSONObject发送给POSTMAN,而不在每个双引号前加斜杠?   java如何获得频域中两个音频信号的比率?   java 安卓 studio理解错误   java插入到部分填充的数组中   java使用流<String>创建流<CustomType>?   java开放式按键应用程序   java获取zxing生成的图像路径   使用shibboleth sso的java授权   java在运行时更改bean类名   javajooq如何从表中选择min'id'   java通过Eclipse web项目运行hadoop mapreduce字数   java同步方法与非同步方法同时执行   方法每次返回一个不同的加密字符数组   java获取ArrayList的每个元素中出现的特定字符的频率<String>