加入收藏 | 设为首页 | 会员中心 | 我要投稿 宿州站长网 (https://www.0557zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 业界 > 正文

Python 中的 HTTP 服务器

发布时间:2019-07-05 12:49:27 所属栏目:业界 来源:Python中文社区
导读:副标题#e# David Wheeler有一句名言:计算机科学中的任何问题,都可以通过加上另一层间接的中间层解决。 为了提高Python网络服务的可移植性,Python社区在PEP 333中提出了Web服务器网关接口(WSGI,Web Server Gateway Interface)。 WSGL标准就是添加了一层

第二个是使用Werkzeug编写的WSGI可调用对象返回当前时间。

  1. #!/usr/bin/env python3 
  2. # A WSGI callable built using Werkzeug. 
  3.  
  4. import time 
  5. from werkzeug.wrappers import Request, Response 
  6.  
  7. @Request.application 
  8. def app(request): 
  9.     host = request.host 
  10.     if ':' in host: 
  11.         host, port = host.split(':', 1) 
  12.     if request.method != 'GET': 
  13.         return Response('501 Not Implemented', status=501) 
  14.     elif host != '127.0.0.1' or request.path != '/': 
  15.         return Response('404 Not Found', status=404) 
  16.     else: 
  17.         return Response(time.ctime()) 

大家可以对比这两个库在简化操作时的不同之处,Werkzeug是Flask框架的基础。

(编辑:宿州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读