这篇文章关键介绍了python django架构键入中国汉字,数据,标识符转成二维码完成详细说明,原文中根据实例代码介绍的十分详尽,对大伙儿的学习或是工作中具备一定的参考学习使用价值,必须的盆友能够参考下

模块必需:Python自然环境 pillow qrcode 模块

关键代码<br>import qrcode
qr = qrcode.QRCode(
      version=2,
      error_correction=qrcode.constants.ERROR_CORRECT_L,
      box_size=20,
      border=4,
    )
qr.add_data('你需要转化成的文档')
qr.make(fit=True)
img = qr.make_image()
# 只必须改为自身的途径
img.save('text.png')  <br># img.save('/Users/admin/PycharmProjects/str_code/statics/assets/png/' 'text.png')

django views涵数代码!路由器自身设定就可以。

from django.shortcuts import render
# Create your views here.
import qrcode
# python-qrcode是个用于生成二维码照片的第三方模块,取决于 PIL 模块和 qrcode 库。
def str_decode_code(request):
  print(request.method)
  if request.method == 'GET':
    return render(request,'index.html')
  if request.method== 'POST':
    text = request.POST.get('message')
    print(text)
    qr = qrcode.QRCode(
      version=2,
      error_correction=qrcode.constants.ERROR_CORRECT_L,
      box_size=20,
      border=4,
    )
    qr.add_data(text)
    qr.make(fit=True)
    img = qr.make_image()
    # 只必须改为自身的途径
    img.save('/Users/admin/PycharmProjects/str_code/statics/assets/png/' 'text.png')
    return render(request,'en_index.html',{'mgs':text}) 

前端代码

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>二维码生成器</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="keywords" content="二维码生成器,二维码扫描,二维码制作,二维码解码,微信二维码,二维码名片,QR code,二维码是啥,微信二维码">
    <meta name="description" content="二维码生成器是中国完全免费二维码在线服务平台,作用简易、便捷、便捷。织梦cms二维码解决方法运用于各种网址,不论是商业服务运用還是自主创业全是优选。">
    <link href="../statics/assets/css/bootstrap.css" rel="external nofollow" rel="stylesheet">
    <link href="../statics/assets/css/bootstrap-colorpicker.min.css" rel="external nofollow" rel="stylesheet">
    <style type="text/css">body {
        padding-top: 60px;
        padding-bottom: 40px;
       }
#flink li a {
  color:#999;
}
    </style>
    <link href="../statics/assets/css/bootstrap-responsive.css" rel="external nofollow" rel="stylesheet">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="../statics/assets/ico/apple-touch-icon-144-precomposed.png.html" rel="external nofollow" >
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="../statics/assets/ico/apple-touch-icon-114-precomposed.png.html" rel="external nofollow" >
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="../statics/assets/ico/apple-touch-icon-72-precomposed.png.html" rel="external nofollow" >
    <link rel="apple-touch-icon-precomposed" href="../statics/assets/ico/apple-touch-icon-57-precomposed.png.html" rel="external nofollow" >
    <link rel="shortcut icon" href="../statics/assets/ico/favicon.png.html" rel="external nofollow" >
  </head>
  <body>
    <div class="navbar navbar-inverse navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>
          </button> <a class="brand" href="index.html" rel="external nofollow" >二维码生成器</a>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="container">
        <header class="jumbotron subhead" id="overview">
           <h1>生成二维码</h1>
          <p class="lead">用以制做生成二维码,便捷各种手机客户端(比如:手机微信、淘宝网、挪动电脑浏览器)开展扫描仪。</p>
        </header>
        <form action="/code/code" method="post">
        <ul id="myTab" class="nav nav-tabs">
          <li class="active"><a href="#" rel="external nofollow" >文字</a>
          </li>
        </ul>
        <div class="row">
          <div class="span5">
            <label>密文:</label>
              <p>
                <textarea name="message" class="span5" style="height: 500px"></textarea>
              </p>
          </div>
          <div class="span2 encrypt_type">
            <button style="margin-top:251080x" class="btn btn-primary" onclick="submsg()" >生成二维码 -></button>
          </div>
          <div class="span5">
            <label>二维码:</label>
            <div style="height: 500px;border:1px solid #000">
{#              照片#}
            </div>
          </div>
        </div>
        </form>
      </div>
      <hr>
      <footer>
{#        <p>CopyRight 2015 <a href="" target=" rel="external nofollow" _blank"></a><strong></strong></p>#}
      </footer>
    </div>
    <script src="../statics/assets/js/jquery-1.11.2.min.js"></script>
    <script src="../statics/assets/js/bootstrap.min.js"></script>
    <script src="../statics/assets/js/bootstrap-colorpicker.js"></script>
{#    <script>#}
{#      function submsg(){#}
{##}
{#      }#}
{#    </script>#}
  </body>
</html>

那样就可以动态性生成二维码了。

搞好的二维码,浏览详细地址:http://qrcode.ipgou.net/

之上便是文中的所有内容,期待对大伙儿的学习有一定的协助,也期待大伙儿多多的适用。