python2--django返回二维码展示页面
# -*- coding:utf-8 -*- from django.shortcuts import render from django.http import JsonResponse,HttpResponse from django.views.generic import Viewimport qrcode,uuid,os # Create your views here. class CreateCode(View): def get(self,request,id,*args,**kwargs): print id code_str = 'helloworld') print code_str filename = self.make_code(code_str) if os.path.exists(filename): qrimg_data = open(filename, 'rb').read() return HttpResponse(qrimg_data, content_type="image/png") def make_code(self,text): qr = qrcode.QRCode(version=5, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=8, border=4, ) # 添加数据 qr.add_data(text) # 生成二维码 qr.make(fit=True) img = qr.make_image() # img.show() filename = 'media/qrcode_all/{uuid}.png'.format(uuid=uuid.uuid4().hex[:8]) img.save(filename) return filename
哈哈😄以上示例效果图因涉及到个人信息,做了处理,谅解
python 中文名:蟒蛇,设计者:Guido van Rossum