WSGIServer 0.2 provides a solid foundation for WSGI-compliant Python web applications. Focus on:
source venv/bin/activate # Linux/Mac
def serve_static_files(environ, start_response): file_path = environ['PATH_INFO'] if os.path.exists(file_path): with open(file_path, 'rb') as file: status = '200 OK' headers = [('Content-Type', 'text/html')] start_response(status, headers) return [file.read()] else: status = '404 Not Found' headers = [('Content-Type', 'text/plain')] start_response(status, headers) return [b'File not found'] wsgiserver 0.2
def __call__(self, environ, start_response): print(f"environ['REQUEST_METHOD'] environ['PATH_INFO']") return self.app(environ, start_response)
# Send response response_data = b''.join(result) self.send_response(response_data, self.status, self.headers_to_send) WSGIServer 0
WSGIServer 0.2 can also be configured using a configuration file. The configuration file should be in INI format.
if == ' main ': server = WSGIServer('0.0.0.0', 8000, hello_world_app) server.serve_forever() wsgiserver 0.2
pip install -r requirements.txt