python之Web Server Gateway Interface
2017-10-03 17:50
429 查看
WSGI是pythonWEB编程的接口 相当于Java的servlet规范
服务器根据规范进行底层网络编程 封装HTTP协议
WEB应用开发更加规范编写应用
由服务器来运行WEB应用
start_response 封装了响应的内容
用environ从PATH_INFO中读取路径参数
服务器根据规范进行底层网络编程 封装HTTP协议
WEB应用开发更加规范编写应用
由服务器来运行WEB应用
根据WSGI编写一个小程序
def application(environ, start_response): start_response('200 ok', [('Content-Type', "text/html")]) return [b'<h1>Hello Web!</h1>']
用python中的wsgiref启动一个服务器
from wsgiref.simple_server import make_server from mark.zhou.my_app import application httpd = make_server('0.0.0.0', 8080, application) print('Server HTTP on port 8000...') httpd.serve_forever() ----------------------------成功访问-------- C:\Python\Python36\python.exe D:/IdeaProjects/python_basic/mark/zhou/my_simple_server.py This is mark __init__.py Server HTTP on port 8000... 127.0.0.1 - - [03/Oct/2017 16:57:03] "GET / HTTP/1.1" 200 19 127.0.0.1 - - [03/Oct/2017 16:57:03] "GET /favicon.ico HTTP/1.1" 200 19 127.0.0.1 - - [03/Oct/2017 16:57:03] "GET /favicon.ico HTTP/1.1" 200 19
def application(environ, start_response):
environ 封装了HTTP请求的内容start_response 封装了响应的内容
用environ从PATH_INFO中读取路径参数
def application(environ, start_response): start_response('200 ok', [('Content-Type', "text/html")]) body = "<h1>Hello {}!</h1>".format(environ['PATH_INFO'][1:] or 'web') return [body.encode("utf-8")]
相关文章推荐
- Introduction to the Python Web Server Gateway Interface (WSGI)
- wsgi (Python Web Server Gateway Interface) ******************
- python wsgi web server gateway interface
- Python Web Server Gateway Interface -- WSGI
- Notes on PEP333 (Python Web Server Gateway Interface)
- Python Web Server Gateway Interface(WSGI)
- Python - 15 Line HTTP Server - Web Interface For Your Tools
- Web Server Gateway Interface (WSGI)
- Python 3.6.0 实现 websocket server
- 为 Python Server Pages 和 Oracle 构建快速 Web 开发环境。
- [转载]FastCGI: A High-Performance Web Server Interface (1)
- Proftp Server Web interface or GUI Tools
- Making a simple web server in Python
- python web server comparison
- python 自带 web服务器-保存为start_server.bat
- simple dynamic web server with self defined framework (python)
- Citrix Access Gateway/Web Interface结合DKEY短信动态密码认证
- Python:FriendFeed的Tornado Web Server
- FastCGI: A High-Performance Web Server Interface 中文翻译版本
- Python:FriendFeed的Tornado Web Server