Python django框架輸入漢字,數(shù)字,字符生成二維碼實(shí)現(xiàn)詳解
這篇文章主要介紹了Python django框架輸入漢字,數(shù)字,字符轉(zhuǎn)成二維碼實(shí)現(xiàn)詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
模塊必備: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">
<h1>生成二維碼</h1>
<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" 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=" 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)生成二維碼了。
做好的二維碼,訪問(wèn)地址:http://qrcode.ipgou.net/
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- python 使用MyQR和qrcode來(lái)制作二維碼
- python-圖片流傳輸?shù)乃悸芳笆纠?url轉(zhuǎn)換二維碼)
- 基于Python生成個(gè)性二維碼過(guò)程詳解
- Python使用qrcode二維碼庫(kù)生成二維碼方法詳解
- Python qrcode 生成一個(gè)二維碼的實(shí)例詳解
- 通過(guò)python掃描二維碼/條形碼并打印數(shù)據(jù)
- 一行Python代碼制作動(dòng)態(tài)二維碼的實(shí)現(xiàn)
- 使用python寫(xiě)的opencv實(shí)時(shí)監(jiān)測(cè)和解析二維碼和條形碼
- Python二維碼生成識(shí)別實(shí)例詳解
- 用python生成(動(dòng)態(tài)彩色)二維碼的方法(使用myqr庫(kù)實(shí)現(xiàn))
- python二維碼操作:對(duì)QRCode和MyQR入門(mén)詳解
- Python3批量生成帶logo的二維碼方法
- Python使用MyQR制作專(zhuān)屬動(dòng)態(tài)彩色二維碼功能
- 用Python給二維碼圖片添加提示文字
相關(guān)文章
Python scikit-learn數(shù)據(jù)預(yù)處理常見(jiàn)方法和步驟
數(shù)據(jù)預(yù)處理是數(shù)據(jù)準(zhǔn)備階段的一個(gè)重要環(huán)節(jié),主要目的是將原始數(shù)據(jù)轉(zhuǎn)換成適合機(jī)器學(xué)習(xí)模型使用的格式,數(shù)據(jù)預(yù)處理可以顯著提高機(jī)器學(xué)習(xí)模型的性能和準(zhǔn)確度,本文給大家介紹了Python數(shù)據(jù)預(yù)處理常見(jiàn)方法和步驟,需要的朋友可以參考下2024-05-05
Python實(shí)現(xiàn)二叉樹(shù)的常見(jiàn)遍歷操作總結(jié)【7種方法】
這篇文章主要介紹了Python實(shí)現(xiàn)二叉樹(shù)的常見(jiàn)遍歷操作,結(jié)合實(shí)例形式總結(jié)分析了二叉樹(shù)的前序、中序、后序、層次遍歷中的迭代與遞歸等7種操作方法,需要的朋友可以參考下2019-03-03
python3使用騰訊企業(yè)郵箱發(fā)送郵件的實(shí)例
今天小編就為大家分享一篇python3使用騰訊企業(yè)郵箱發(fā)送郵件的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-06-06
聊聊pytorch測(cè)試的時(shí)候?yàn)楹我由蟤odel.eval()
這篇文章主要介紹了聊聊pytorch測(cè)試的時(shí)候?yàn)楹我由蟤odel.eval()的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05
python過(guò)濾字符串中不屬于指定集合中字符的類(lèi)實(shí)例
這篇文章主要介紹了python過(guò)濾字符串中不屬于指定集合中字符的類(lèi),涉及Python針對(duì)字符串與集合的相關(guān)操作技巧,需要的朋友可以參考下2015-06-06
pytorch實(shí)現(xiàn)從本地加載 .pth 格式模型
今天小編就為大家分享一篇pytorch實(shí)現(xiàn)從本地加載 .pth 格式模型,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-02-02
Python實(shí)現(xiàn)多張圖片合成一張馬賽克圖片
這篇文章主要介紹了了Python如何實(shí)現(xiàn)將多張圖片合成一張馬賽克圖片。文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Python有一定的幫助,感興趣的可以學(xué)習(xí)一下2021-12-12
Python異常之常見(jiàn)的Bug類(lèi)型解決方法
這篇文章主要介紹了Python異常之常見(jiàn)的Bug類(lèi)型解決方法,主要分享一些粗心導(dǎo)致和知識(shí)不熟練導(dǎo)致的語(yǔ)法錯(cuò)誤以及被迫掉坑等內(nèi)容,文章介紹非常詳細(xì)需要的小伙伴可以參考一下2022-03-03
python爬取晉江文學(xué)城小說(shuō)評(píng)論(情緒分析)
這篇文章主要介紹了使用python爬取晉江文學(xué)城小說(shuō)評(píng)論(情緒分析),全文代碼詳細(xì),邏輯清晰,很適合學(xué)習(xí)爬蟲(chóng)爬取的朋友,需要的朋友可以參考下2021-04-04

