WSGI Server

Posted xufengfan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WSGI Server相关的知识,希望对你有一定的参考价值。

WSGI Server

server.py

from wsgiref.simple_server import make_server
from app import application

httpd = make_server('0.0.0.0', 8080, application)
print('start http server 8080...')

httpd.serve_forever()

app.py

def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    print(environ['PATH_INFO'])
    body = '<h1>Hello, %s!</h1>' % (environ['PATH_INFO'][1:] or 'web')
    return [body.encode('utf-8')]

好了,打开浏览器,输入127.0.0.1:8080/helloworld/

注意,server.py运行时可能会卡住,可以反复运行一次,浏览器就能访问到了

任何复杂的web服务,本质还是源于此

以上是关于WSGI Server的主要内容,如果未能解决你的问题,请参考以下文章

WSGI Server

简单的WSGI server

Microsoft SQL Server 代码片段收集

缺少 SQL SERVER 2014 代码片段

此 WSGI 应用程序无法访问守护进程:/mod.wsgi

浅析WSGI协议