示例wsgiserver.py

 1#!/usr/bin/python
 2"""WSGI server example"""
 3from __future__ import print_function
 4from gevent.pywsgi import WSGIServer
 5
 6
 7def application(env, start_response):
 8    if env['PATH_INFO'] == '/':
 9        start_response('200 OK', [('Content-Type', 'text/html')])
10        return [b"<b>hello world</b>"]
11
12    start_response('404 Not Found', [('Content-Type', 'text/html')])
13    return [b'<h1>Not Found</h1>']
14
15
16if __name__ == '__main__':
17    print('Serving on 8088...')
18    WSGIServer(('127.0.0.1', 8088), application).serve_forever()

Current source

Next page: 示例wsgiserver_ssl.py