這篇文章給大家分享的是有關(guān)Python中django框架輸入漢字,數(shù)字,字符生成二維碼的示例分析的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
創(chuàng)新互聯(lián)自2013年起,是專(zhuān)業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元上蔡做網(wǎng)站,已為上家服務(wù),為上蔡各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792模塊必備:Python環(huán)境 + 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函數(shù)代碼!路由自己設(shè)置就可以。
from django.shortcuts import render # Create your views here. import qrcode # python-qrcode是個(gè)用來(lái)生成二維碼圖片的第三方模塊,依賴(lài)于 PIL 模塊和 qrcode 庫(kù)。 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="二維碼生成器是國(guó)內(nèi)免費(fèi)二維碼在線服務(wù)網(wǎng)站,功能簡(jiǎn)單、方便、快捷??棄?mèng)二維碼解決方案應(yīng)用于各類(lèi)網(wǎng)站,無(wú)論是商業(yè)應(yīng)用還是個(gè)人創(chuàng)業(yè)都是選。"> <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"> <h2>生成二維碼</h2> <p class="lead">用于制作生成二維碼,方便各類(lèi)客戶(hù)端(例如:微信、淘寶、移動(dòng)瀏覽器)進(jìn)行掃描。</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" ></textarea> </p> </div> <div class="span2 encrypt_type"> <button class="btn btn-primary" onclick="submsg()" >生成二維碼 -></button> </div> <div class="span5"> <label>二維碼:</label> <div > {# 圖片#} </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>
這樣就可以動(dòng)態(tài)生成二維碼了。
感謝各位的閱讀!關(guān)于“Python中django框架輸入漢字,數(shù)字,字符生成二維碼的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
網(wǎng)站欄目:Python中django框架輸入漢字,數(shù)字,字符生成二維碼的示例分析-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)網(wǎng)址:http://muchs.cn/article30/cdchso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、網(wǎng)頁(yè)設(shè)計(jì)公司、面包屑導(dǎo)航、App開(kāi)發(fā)、微信小程序、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容