标签:技术分享 soc model django res eve padding ima 请求
#!/usr/bin/env python#coding:utf-8import socket#客户端def handle_request(client):buf = client.recv(1024)client.send("HTTP/1.1 200 OK\r\n\r\n")client.send("Hello,Seven")#服务器端def main():sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)sock.bind((‘localhost‘,8000))sock.listen(5)while True:connection,address = sock.accept()handle_request(connection)connection.close()if __name__ == "__main__":main()
#coding:utf-8from wsgiref.simple_server import make_serverdef RunServer(environ, start_response):start_response(‘200 OK‘, [(‘Content-Type‘, ‘text/html‘)])return ‘<h1>Hello, web!</h1>‘if __name__ == ‘__main__‘:httpd = make_server(‘‘, 8000, RunServer)print "Serving HTTP on port 8000..."httpd.serve_forever()
#!/usr/bin/env python#coding:utf-8from wsgiref.simple_server import make_serverdef index():return ‘index‘def login():return ‘login‘def routers():urlpatterns = ((‘/index/‘,index),(‘/login/‘,login),)return urlpatternsdef RunServer(environ, start_response):start_response(‘200 OK‘, [(‘Content-Type‘, ‘text/html‘)])url = environ[‘PATH_INFO‘]urlpatterns = routers()func = Nonefor item in urlpatterns:if item[0] == url:func = item[1]breakif func:return func()else:return ‘404 not found‘if __name__ == ‘__main__‘:httpd = make_server(‘‘, 8000, RunServer)print "Serving HTTP on port 8000..."httpd.serve_forever()
MVC与MTV都只是文件的堆放模式Model 数据库交互Template 页面展示View 逻辑处理
标签:技术分享 soc model django res eve padding ima 请求
原文地址:http://www.cnblogs.com/PythonHomePage/p/7634374.html