python---web框架本质(1)

总的来说php相对较为简单,但是内部封装太多,不利于对编程的更本质探索。

但是对于生产开发确实是一门不错的语言。python对于socket以及web框架的理解更加透彻

# coding:utf8
# __author:  Administrator
# date:      2018/3/5 0005
# /usr/bin/env python
from wsgiref.simple_server import  make_server

#直接返回html字符
def new():
    return "<h1>this is a news page</h1>"

def index():
    return "<h1>this is a index page</h1>"


#改进,读取文件
def showFile():
    fp = open("04模态对话框.html",'r')
    content = fp.read()
   fp.close() 
return content #类似中间件 URLS ={ "/new":new, "/index":index, "/show":showFile, } def RunServer(environ, start_respone): start_respone('200 OK',[('Content-Type','text/html')]); url = environ['PATH_INFO'] #用户访问路径 if url in URLS.keys(): func_name = URLS[url] ret = func_name() else: ret = "<h1 style='color:red;'>404</h1>" return ret if __name__ == "__main__": httpd=make_server('',8080,RunServer) httpd.serve_forever()

这一方法缺少文件的分类不满足MVC标准,毕竟只是初识(再次理解)

原文地址:https://www.cnblogs.com/ssyfj/p/8508758.html