有一天,一个同事每次打包发布都要把app放到一个目录中,还需要把这个打包文件再发给同事测试,这样就很麻烦,我说好像我可以解决这个问题,当时想用nodejs的可是还不是特别熟,后来就用了刚学的sanic框架搭建了一个内网文件访问服务。
以下是代码
import os from sanic import Sanic, response app = Sanic('test_static') app.static('/static', '../static') @app.route('/static') async def static(request): listdir_files = os.listdir('../static/') result = '<br>'.join(['<a href="{}">{}</a>'.format(request.url + '/' + i, i) for i in listdir_files]) return response.html(result) if __name__ == '__main__': app.run(host='0.0.0.0', debug=True)
这个是结果:
点击即可下载,除了浏览器可以渲染的文件