对bareasgi的静态文件支持
bareasgi-static的Python项目详细描述
Bareasgi静态
对bareASGI的静态文件支持(读取documentation)
概述
这个包支持向bareasgi提供静态文件。
用法
以下示例提供单个文件。
importuvicornimportos.pathfrombareasgiimportApplicationfrombareasgi_staticimportfile_responsehere=os.path.abspath(os.path.dirname(__file__))asyncdefhttp_request_callback(scope,info,matches,content):returnawaitfile_response(scope,200,os.path.join(here,'file_stream.html'))app=Application()app.http_router.add({'GET'},'/example1',http_request_callback)uvicorn.run(app,port=9010)
下一个示例提供给定目录下的文件。
importos.pathimportuvicornfrombareasgiimportApplicationfrombareasgi_staticimportadd_static_file_providerhere=os.path.abspath(os.path.dirname(__file__))app=Application()add_static_file_provider(app,os.path.join(here,simple_www),index_filename='index.html')uvicorn.run(app,port=9010)