Python django frame using the input characters, numbers, characters, and the like. . Turn into a two-dimensional code!
Modules necessary: Python environment + pillow + qrcode module
Core code
Import qrcode QR = qrcode.QRCode ( Version = 2, error_correction = qrcode.constants.ERROR_CORRECT_L, box_size = 20 is, border =. 4, ) qr.add_data ( 'your file to be generated') qr.make (= True Fit ) IMG = qr.make_image () # only need to change their path img.save ( 'text.png')
# img.save ( '/ the Users / ADMIN / PycharmProjects / str_code / statics to / Assets / PNG /' + ' text.png ')
django views the function code! They can set up their own route.
Import the render django.shortcuts from # the Create your views here Wallpaper. Import qrcode # Python-qrcode is used to generate two-dimensional code picture of third-party modules, depending on the PIL module and qrcode library. str_decode_code DEF (Request): Print (request.method) IF request.method == 'the GET': return the render (Request, 'index.html') IF request.method == 'the POST': text = request.POST.get ( 'Message') Print (text) QR = qrcode.QRCode ( Version = 2, error_correction = qrcode.constants.ERROR_CORRECT_L, box_size = 20 is, border =. 4, ) qr.add_data (text) qr.make (Fit = True) = qr.make_image IMG () # only need to change their path img.save ( '/ the Users / ADMIN / PycharmProjects / str_code / statics to / Assets / PNG /' + 'text.png') return the render (Request, 'en_index .html ', {' mgs': text})
Anterior Code
<! DOCTYPE HTML> <HTML lang = "EN"> <head> <Meta charset = "UTF-. 8"> <title> two-dimensional code generator </ title> <Meta name = "the viewport" Content = "width = width-device, Initial-Scale = 1.0 "> <Meta name =" Keywords "Content =" two-dimensional code generator, a two-dimensional code scanning, produce two-dimensional code, the two-dimensional code decoding, micro-channel two-dimensional code, the two-dimensional code business cards, QR code, what is a two-dimensional code, the two-dimensional micro-letter code "> <Meta name =" the Description "Content =" two-dimensional code generator is the two-dimensional code free online service, features a simple, convenient and fast. weave dream dimensional code solutions used in various websites, whether it is commercial or personal business applications are preferred. "> <Link href =" ../ statics / Assets / CSS / bootstrap.css "rel =" stylesheet "> < link href = "../ statics / assets / css / bootstrap-colorpicker.min.css" 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="stylesheet"> <link rel="apple-touch-icon-precomposed" sizes="144x144" href="../statics/assets/ico/apple-touch-icon-144-precomposed.png.html"> <link rel="apple-touch-icon-precomposed" sizes="114x114" href="../statics/assets/ico/apple-touch-icon-114-precomposed.png.html"> <link rel="apple-touch-icon-precomposed" sizes="72x72" href="../statics/assets/ico/apple-touch-icon-72-precomposed.png.html"> <link rel="apple-touch-icon-precomposed" href="../statics/assets/ico/apple-touch-icon-57-precomposed.png.html"> <link rel="shortcut icon" href="../statics/assets/ico/favicon.png.html"> </head> <body> <div class="navbar navbar-inverse navbar-fixed-top"> <header class="jumbotron subhead" id="overview"> <form action="/code/code" method="post"> <ul id="myTab" class="nav nav-tabs"> <li class="active"><a href="#">文本</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:250px" 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="_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>
So that it can dynamically generate a two-dimensional code.
Make two-dimensional code, access address: http://qrcode.ipgou.net/