Skip to main content

WSGI Middleware for serving static files

Project description

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

WSGI Middleware for serving static files.

Usage

import os
from wsgiref.simple_server import make_server
from wsgi_static_middleware import StaticMiddleware

BASE_DIR = os.path.dirname(__name__)
STATIC_DIRS = [os.path.join(BASE_DIR, 'static')]


def app(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 2016 03: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 2016 03:42:1473532953S GMT
< Accept-Ranges: bytes
<
.foo {
    font-size: 10px;
}
* Closing connection 0

LICENSE

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wsgi-static-middleware-0.1.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wsgi_static_middleware-0.1.2-py2-none-any.whl (6.6 kB view details)

Uploaded Python 2

File details

Details for the file wsgi-static-middleware-0.1.2.tar.gz.

File metadata

File hashes

Hashes for wsgi-static-middleware-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7d58564cc74ff53d00d9973a9533685081343ee0cb929b0a1a1b4f2a17f6e2a1
MD5 12559427b203f0adb26ab27ef3959a5d
BLAKE2b-256 d7cc33e2b7b152139154b44d35dc69a60c33cff6050eed90ee2cef8e77702203

See more details on using hashes here.

File details

Details for the file wsgi_static_middleware-0.1.2-py2-none-any.whl.

File metadata

File hashes

Hashes for wsgi_static_middleware-0.1.2-py2-none-any.whl
Algorithm Hash digest
SHA256 e77aa5e2bd432d9b6b56d44a23c67a520309439ea888749e3d012cd7ff6eeda2
MD5 21fb1972d69ae92a38980d07b11407e3
BLAKE2b-256 f96c03fc86dcf25fb3b60dc81027ef06dc9c308bb00f0fa79d241263eb391099

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page