在Django中,我尝试记录请求和响应内容长度,这与Django服务器打印到stderr的内容完全相同.
[05/Apr/2011 22:59:08] "GET /pages/ HTTP/1.1" 200 332161
[05/Apr/2011 22:59:15] "GET /pages/12 HTTP/1.1" 301 0
[05/Apr/2011 22:59:15] "GET /pages/12/ HTTP/1.1" 200 361474
[05/Apr/2011 22:59:16] "GET /pages/12/load/tags/ HTTP/1.1" 200 13899
[05/Apr/2011 22:59:16] "GET /pages/12/load/comments/ HTTP/1.1" 200 82
Run Code Online (Sandbox Code Playgroud)
所以,我写了一个简单的中间件如下,但是,'Content-Length'的值总是空的.
class LogHttpResponse(object):
def process_response(self, request, response):
import datetime
print response.items()
time_text = datetime.datetime.now().strftime('%m/%d/%Y %H:%M:%S')
print '[%s] "%s %s" %d %s' % (time_text, request.method, request.path,
response.status_code,
response.get('Content-Length', ''))
return response
Run Code Online (Sandbox Code Playgroud)
我通过fire-debug检查过,响应头中有'Content-Length'.但是中间件中没有"内容长度","print response.items()"显示:
[('Content-Type', 'text/html; charset=utf-8')]
Run Code Online (Sandbox Code Playgroud)
中间件订单有什么问题吗?
我想通过python编写一些安装脚本,它应该知道操作系统选择apt命令或yum命令.
似乎sys.platform可以告诉'win32'或其他人,但是如何知道它正在使用Python中的Debian或CentOS?