간단한 웹 프레임워크 구현

7085 단어

간단한 웹 프레임워크 구현


  
  
  
  
  1. #!/usr/bin/env python
  2. # -- coding: utf-8 --
  3. __author__ = 'EchoRep'
  4. from wsgiref.simple_server import make_server
  5. def index():
  6. #
  7. data = open('html/index.html').read()
  8. return data
  9. def echo():
  10. #
  11. data = open('html/echo.html').read()
  12. return data
  13. url_list=[
  14. ('/echo',echo),
  15. ('/index',index),
  16. ]
  17. def RunServer(environ,start_response):
  18. start_response('200 OK',[('Content-Type','text/html')])
  19. #
  20. #
  21. #
  22. request_url = environ['PATH_INFO']
  23. #
  24. #
  25. #
  26. #
  27. #
  28. #
  29. #
  30. for url in url_list:
  31. if request_url == url[0]:
  32. return url[1]()
  33. else:
  34. return "404"
  35. if __name__ == '__main__':
  36. httpd = make_server('',8000,RunServer)
  37. print "Server HTTP on port 8000..."
  38. httpd.serve_forever()


(Wiz)


좋은 웹페이지 즐겨찾기