深入了解一下PYTHON中关于SOCKETSERVER的模块-A

简介: 有了这块知识,应该对各类WEB框架有更好的理解吧。。FLASK,DJANGO,WEBPY。。。。 #!/usr/bin/env python from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler class Re...

有了这块知识,应该对各类WEB框架有更好的理解吧。。FLASK,DJANGO,WEBPY。。。。

#!/usr/bin/env python

from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler

class RequestHandler(BaseHTTPRequestHandler):
    def _writeheaders(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()

    def do_HEAD(self):
        self._writeheaders()

    def do_GET(self):
        self._writeheaders()
        self.wfile.write("""
        <HTML><HEAD><TITLE>sample python page</TITLE></HEAD>
        <BODY> THIS IS A SAMPLE PAGE.
        </BODY></HTML>""")
serveraddr = ('',8765)
srvr = HTTPServer(serveraddr, RequestHandler)
srvr.serve_forever()

目录
相关文章
|
15天前
|
机器学习/深度学习 存储 Python
|
2天前
|
Python Windows
python中的异常与模块
python中的异常与模块
8 1
|
11天前
|
JSON 数据格式 Python
Python标准库中包含了json模块,可以帮助你轻松处理JSON数据
【4月更文挑战第30天】Python的json模块简化了JSON数据与Python对象之间的转换。使用`json.dumps()`可将字典转为JSON字符串,如`{&quot;name&quot;: &quot;John&quot;, &quot;age&quot;: 30, &quot;city&quot;: &quot;New York&quot;}`,而`json.loads()`则能将JSON字符串转回字典。通过`json.load()`从文件读取JSON数据,`json.dump()`则用于将数据写入文件。
16 1
|
12天前
|
Python
Python实现压缩解压---tarfile模块详解
Python实现压缩解压---tarfile模块详解
|
12天前
|
Linux Python Windows
Python中time和datetime模块详解
Python中time和datetime模块详解
|
12天前
|
存储 Linux 数据安全/隐私保护
python的压缩模块zipfile详解
python的压缩模块zipfile详解
|
12天前
|
Linux Python Windows
python的os模块详细解读(二)
python的os模块详细解读(二)
|
12天前
|
移动开发 Linux Shell
python的os模块详细解读(一)
python的os模块详细解读(一)
python的os模块详细解读(一)
|
12天前
|
Python 容器
python内置函数、数学模块、随机模块(二)
python内置函数、数学模块、随机模块(二)
|
12天前
|
索引 Python
python内置函数、数学模块、随机模块(一)
python内置函数、数学模块、随机模块(一)