1.场景
- 将URL动态生成二维码前端展示(微信支付等,)--》
1.静态文件路径访问
返回URL_name,(a标签,src 静态路由访问)
2.流传输,前端渲染
二进制流返回前端,前端根据二进制流编码类型显示
3.前端js生成
后台获取到微信支付的code_url,前端js将code_url生成二维码,并渲染
- 实际代码
使用python_web 框架--》tornado
manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import os import asyncio import tornado.ioloop import tornado.httpserver import tornado.web import tornado.options from tornado.options import define, options, parse_command_line from apps import UrlHandler, Url2Handler, Url3Handler define( "port" , default = 8000 , type = int ) def create_app(): settings = { "template_path" : os.path.join(os.path.dirname(__file__), "templates" ), "static_path" : os.path.join(os.path.dirname(__file__), "static" ), } application = tornado.web.Application( handlers = [ (r "/url" , UrlHandler), (r "/url2" , Url2Handler), (r "/url3" , Url3Handler), ], debug = True , * * settings, ) return application if __name__ = = '__main__' : parse_command_line() app = create_app() server = tornado.httpserver.HTTPServer(app) server.listen(options.port) asyncio.get_event_loop().run_forever() |
apps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
import tornado.web from manager_handler import gen_qrcode, gen_qrcode_obj,gen_qrcode_buf class BaseHandler(tornado.web.RequestHandler): pass class UrlHandler(BaseHandler): def get( self ): # 获取链接 self .render( 'qrcode.html' , title = 'url' , data = 'URL-提交' , img_stream = '') async def post( self ): # 生成二维码 url = self .get_argument( 'url_str' ) # URL转换二维码 img_stream = gen_qrcode(url) await self .render( 'qrcode.html' , title = 'qrcode' , data = '扫码支付' , img_stream = img_stream) class Url2Handler(BaseHandler): def get( self ): # 获取链接 self .render( 'qrcode.html' , title = 'url' , data = 'URL-提交' , img_stream = '') async def post( self ): # 生成二维码 url = self .get_argument( 'url_str' ) # URL转换二维码 img_stream = gen_qrcode_obj(url = url) # await self.render('qrcode.html', id="codetool">
manager_handler.py
base.html
qrcode.html
以上就是python-图片流传输的思路及示例(url转换二维码)的详细内容,更多关于python 图片流传输的资料请关注服务器之家其它相关文章! 原文链接:https://www.cnblogs.com/yblackd/p/13224404.html 相关文章
热门资讯 |