欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python django框架輸入漢字,數(shù)字,字符生成二維碼實(shí)現(xiàn)詳解

 更新時(shí)間:2019年09月24日 10:46:43   作者:張丶耀慶  
這篇文章主要介紹了Python django框架輸入漢字,數(shù)字,字符轉(zhuǎn)成二維碼實(shí)現(xiàn)詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

這篇文章主要介紹了Python django框架輸入漢字,數(shù)字,字符轉(zhuǎn)成二維碼實(shí)現(xiàn)詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(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è)用來生成二維碼圖片的第三方模塊,依賴于 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="二維碼生成器是國內(nèi)免費(fèi)二維碼在線服務(wù)網(wǎng)站,功能簡單、方便、快捷。織夢二維碼解決方案應(yīng)用于各類網(wǎng)站,無論是商業(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">用于制作生成二維碼,方便各類客戶端(例如:微信、淘寶、移動瀏覽器)進(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>

這樣就可以動態(tài)生成二維碼了。

做好的二維碼,訪問地址:http://qrcode.ipgou.net/

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 利用Python編寫的實(shí)用運(yùn)維腳本分享

    利用Python編寫的實(shí)用運(yùn)維腳本分享

    Python在很大程度上可以對shell腳本進(jìn)行替代。筆者一般單行命令用shell,復(fù)雜點(diǎn)的多行操作就直接用Python了。本文歸納了Python中一些實(shí)用腳本操作,需要的可以參考一下
    2022-05-05
  • python實(shí)現(xiàn)繪制樹枝簡單示例

    python實(shí)現(xiàn)繪制樹枝簡單示例

    這篇文章主要介紹了python實(shí)現(xiàn)繪制樹枝簡單示例,有助于讀者加深對Python繪圖的認(rèn)識,需要的朋友可以參考下
    2014-07-07
  • Python中的yield全方位解讀

    Python中的yield全方位解讀

    這篇文章主要介紹了Python中的yield全方位解讀,在 Python 中,使用了 yield 的函數(shù)被稱為生成器,跟普通函數(shù)不同的是,生成器是一個(gè)返回迭代器的函數(shù),只能用于迭代操作,更簡單點(diǎn)理解生成器就是一個(gè)迭代器,需要的朋友可以參考下
    2023-08-08
  • Python小進(jìn)度條顯示代碼

    Python小進(jìn)度條顯示代碼

    今天小編就為大家分享一篇關(guān)于Python小進(jìn)度條顯示代碼,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • 詳解Python Matplot中文顯示完美解決方案

    詳解Python Matplot中文顯示完美解決方案

    這篇文章主要介紹了Python Matplot中文顯示完美解決方案,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • Python學(xué)習(xí)之MRO方法搜索順序

    Python學(xué)習(xí)之MRO方法搜索順序

    這篇文章主要介紹了Python MRO方法搜索順序,文中代碼和圖片解釋的非常詳細(xì),可以很好的帶大家學(xué)習(xí)相關(guān)知識內(nèi)容,感興趣的小伙伴可以參考一下這篇文章
    2021-09-09
  • pytorch制作自己的LMDB數(shù)據(jù)操作示例

    pytorch制作自己的LMDB數(shù)據(jù)操作示例

    這篇文章主要介紹了pytorch制作自己的LMDB數(shù)據(jù)操作,結(jié)合實(shí)例形式分析了pytorch使用lmdb的相關(guān)操作技巧與使用注意事項(xiàng),需要的朋友可以參考下
    2019-12-12
  • Flask框架debug與配置項(xiàng)的開啟與設(shè)置詳解

    Flask框架debug與配置項(xiàng)的開啟與設(shè)置詳解

    這篇文章主要介紹了Flask框架debug與配置項(xiàng)的開啟與設(shè)置,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-09-09
  • python ftplib模塊使用代碼實(shí)例

    python ftplib模塊使用代碼實(shí)例

    這篇文章主要介紹了python ftplib模塊使用代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-12-12
  • python使用tomorrow實(shí)現(xiàn)多線程的例子

    python使用tomorrow實(shí)現(xiàn)多線程的例子

    今天小編就為大家分享一篇python使用tomorrow實(shí)現(xiàn)多線程的例子,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-07-07

最新評論