服务静态文件的wsgi中间件

wsgi-static-middleware的Python项目详细描述


https://travis-ci.org/kobinpy/wsgi-static-middleware.svg?branch=masterhttps://badge.fury.io/py/wsgi-static-middleware.svg

用于服务静态文件的wsgi中间件。

用法

importosfromwsgiref.simple_serverimportmake_serverfromwsgi_static_middlewareimportStaticMiddlewareBASE_DIR=os.path.dirname(__name__)STATIC_DIRS=[os.path.join(BASE_DIR,'static')]defapp(env,start_response):start_response('200 OK',[('Conte-type','text/plain; charset=utf-8')])return[b'Hello World']app=StaticMiddleware(app,static_root='static',static_dirs=STATIC_DIRS)if__name__=='__main__':httpd=make_server('',8000,app)httpd.serve_forever()
$ curl -v localhost:8000/static/style.css
*   Trying ::1...
* connect to ::1 port 8000 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8000(#0)
> GET /static/style.css HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.43.0
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Date: Sun, 11 Sep 201603:42:33 GMT
< Server: WSGIServer/0.2 CPython/3.5.1
< Content-Encodings:
< Content-Type: text/css;charset=UTF-8
< Content-Length: 30
< Last-Modified: Sun, 11 Sep 201603:42:1473532953S GMT
< Accept-Ranges: bytes
<
.foo {
    font-size: 10px;}
* Closing connection 0

许可证

MIT License

Copyright (c) 2016 Masashi SHIBATA

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么这段代码要打印空字符串?   java未知错误:由于标签页崩溃,会话被删除   布尔型上的java函数if-else   java最佳蚂蚁教程/快速入门?   JAVAutil。java中的扫描程序跳过do while循环中的扫描程序输入   java我们可以在selenium中使用ExpectedConditions和FluentWait来实现通用等待方法吗?   java如何使用gson库解析JSONObject   java GWT模拟Android LinearLayout的布局重量属性?   Java正则表达式重写日期表达式   java MediaPlayer播放我的MP3文件,但非常安静   java背景不显示javaFX   用于CLI的java quarkus开发模式,如何重新启动应用程序   websphere WSJdbcDataSource的java Jar文件   java Spring 4对象不会自动连接变量   java从Dbpedia定制本体/RDF图