From cec957d7564d5f0f7e062d7743f08eb848046c6b Mon Sep 17 00:00:00 2001 From: janda <158464459@qq.com> Date: 2017年11月29日 11:13:14 +0800 Subject: [PATCH] =?UTF-8?q?WEB=20=E5=BC=80=E5=8F=91=E3=80=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0WSGI=E6=8E=A5=E5=8F=A3=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/server.py | 18 ++++++++++++++++++ web/wsgi_py.py | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 web/server.py create mode 100644 web/wsgi_py.py diff --git a/web/server.py b/web/server.py new file mode 100644 index 0000000..8c10149 --- /dev/null +++ b/web/server.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# 从wsgiref模块导入: +from wsgiref.simple_server import make_server +# 导入我们自己编写的application函数: +from wsgi_py import application + +''' + 负责启动wsgi接口的服务 +''' +__author__ = "佚名" + +# 创建一个服务器 +httpd = make_server("", 8888, application) +print("Serving HTTP on port 8888...") +# 开始监听HTTP请求: +httpd.serve_forever() + diff --git a/web/wsgi_py.py b/web/wsgi_py.py new file mode 100644 index 0000000..776ee13 --- /dev/null +++ b/web/wsgi_py.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +''' + WSGI接口实现 + + 请求地址:http://localhost:8888/xxx +''' +__author__ = "佚名" + +def application(environ, start_response): + start_response("200 OK", [("Content-Type", "text/html")]) + # 获取请求参数 + result = "

Hello, %s !

" % environ["PATH_INFO"][1:] + return [result.encode("utf-8")] + + +# 主函数 +if __name__ == "__main__": + pass \ No newline at end of file

AltStyle によって変換されたページ (->オリジナル) /