zoukankan      html  css  js  c++  java
  • 基于django的生成二维码的接口

    原理就是在视图层写一个将数据生成二维码的视图函数:

    def generate_qrcode(request, data):
        img = qrcode.make(data)
    
        buf = BytesIO()
        img.save(buf)
        image_stream = buf.getvalue()
    
        response = HttpResponse(image_stream, content_type='image/png')
        return response

    然后在urls.py中注册路由:

        url(r'^qrcode/(.+)$', generate_qrcode, name='qrcode')

    启动服务器就可以使用自己的接口去生成二维码了。

    构造函数的时候要导入两个包:

    import qrcode
    from django.http import HttpResponse
    from django.utils.six import BytesIO
  • 相关阅读:
    html 3
    html标签2
    html标签
    2017.4.27
    2017.4.26
    2017.4.25
    2017.4.20
    2017.1.18
    2017.4.17
    2017.4.16.
  • 原文地址:https://www.cnblogs.com/zzy0306/p/8427299.html
Copyright © 2011-2022 走看看