新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python中django框架輸入漢字,數(shù)字,字符生成二維碼的示例分析-創(chuàng)新互聯(lián)
這篇文章給大家分享的是有關(guān)Python中django框架輸入漢字,數(shù)字,字符生成二維碼的示例分析的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。
模塊必備:Python環(huán)境 + pillow + qrcode 模塊
核心代碼
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')
# 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è)用來生成二維碼圖片的第三方模塊,依賴于 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})
前段代碼
二維碼生成器 {# #}生成二維碼
用于制作生成二維碼,方便各類客戶端(例如:微信、淘寶、移動(dòng)瀏覽器)進(jìn)行掃描。
這樣就可以動(dòng)態(tài)生成二維碼了。
感謝各位的閱讀!關(guān)于“Python中django框架輸入漢字,數(shù)字,字符生成二維碼的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
分享題目:Python中django框架輸入漢字,數(shù)字,字符生成二維碼的示例分析-創(chuàng)新互聯(lián)
分享鏈接:http://www.ef60e0e.cn/article/cdchso.html