URI:Uniform Resource Identifier,即统一资源标志符,用来唯一的标识一个资源。
URL:Uniform Resource Locator,统一资源定位符。即URL可以用来标识一个资源,而且还指明了如何locate这个资源。
URN:Uniform Resource Name,统一资源命名。即通过名字来表示资源的。
查询字符串:?开头,参数对之间&连接
WSGI
WSGI允许开发者将选择web框架和web服务器分开。可以混合匹配web服务器和web框架,选择⼀个适合的配对。⽐如,可以在Gunicorn 或者Nginx/uWSGI 或者 Waitress上运⾏ Django, Flask, 或 Pyramid。真正的混合匹配,得益于WSGI同时⽀持服务器和架构。
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return 'Hello World!'
上⾯的 application() 函数就是符合WSGI标准的⼀个HTTP处理函数,它接收两个参数:
environ:⼀个包含所有HTTP请求信息的dict对象;
start_response:⼀个发送HTTP响应的函数。
一些代码:
获得文件运行时的参数
sys.path.insert(1, WSGI_PYTHON_DIR)
if len(sys.argv) < 2:
sys.exit("python MyWebServer.py Module:app")
# python MyWebServer.py MyWebFrameWork:app
module_name, app_name = sys.argv[1].split(":")
动态导入一个类
m = __import__(module_name)
app = getattr(m, app_name)
http_server = HTTPServer(app)
Application(object)中的call类:
![](https://img.haomeiwen.com/i7485616/7893ea12d91f0e4c.png)
网友评论