python 2.7.12生成二维码网页分别在windows以及linux

windows环境下

# -*- coding: utf-8 -*-
import sys
import qrcode

sys.setdefaultencoding('utf-8')
class Trains(object):
table = 't_trains'
trains = None
targetHelp = 'code'
actionHelp = {
'code':'id_train',
}
  def __init__(self,**trains):
  self.trains = trains
  # 生成二维码
  def code(self):
    data = 'http://xxx.xxx.com/xxx.html?id_train=' + self.trains['id_train']
    img_file = 'C:/Users/Public/Desktop/' + self.trains['id_train'] + '.png'
    img = qrcode.make(data)
    # 图片数据保存至本地文件
    img.save(img_file)
    # 显示二维码图片
    img.show()
    def make(data=None, **kwargs):
    qr = QRCode(**kwargs)
    qr.add_data(data)
    return qr.make_image()

    actionExec = {
      'code':code
    }


linux环境下

# -*- coding: utf-8 -*-
import sys
import qrcode

sys.setdefaultencoding('utf-8')
class Trains(object):
  table = 't_trains'
  trains = None
  targetHelp = 'code'
  actionHelp = {
    'code':'id_train',
  }
  def __init__(self,**trains):
  self.trains = trains

  # 生成二维码
  def code(self):
    data = 'http://xxx.xxx.com/xxx.html?id_train='+self.trains['id_train']
    img_file = '/www/wwwroot/xxx/code/'+self.trains['id_train']+'.png'
    img = qrcode.make(data)
    # 图片数据保存至本地文件
    img.save(img_file)
    # 显示二维码图片
    img.show()
    def make(data=None, **kwargs):
    qr = QRCode(**kwargs)
    qr.add_data(data)
    return qr.make_image()

    actionExec = {
      'code':code
    }

 

posted on 2018-10-18 15:54  十五岁少年  阅读(378)  评论(0编辑  收藏  举报