zoukankan      html  css  js  c++  java
  • web框架实例

    s5.py

    from wsgiref.simple_server import make_server
    def handle_index():
        return [b'<h1>Hello,Index!</h1>']
    def handle_date():
        return [b'<h1>Hello,Date!</h1>']

    def RunServer(environ,start_response):
        # environ 客户发来的所有数据
        # start_response
    封装要返回给用户的数据响应状态码
       
    start_response('200 ok',[('Content-Type','text/html')])
        #返回的内容
       
    current_url=environ["PATH_INFO"]
        if current_url=="/index":
            return handle_index()
        elif current_url=="/date":
            return handle_date()
        else:
            return [b'<h1>404</h1>']

    if __name__=="__main__":
        httpd=make_server('',8000,RunServer)
        print("server http on port 8000...")
        httpd.serve_forever()

    s6.py

    from wsgiref.simple_server import make_server
    def handle_index():
        return [b'<h1>Hello,Index!</h1>']
    def handle_date():
        return [b'<h1>Hello,Date!</h1>']

    URL_DICT={
        "/index":handle_index,
        "/date":handle_date,
    }
    def RunServer(environ,start_response):
        # environ 客户发来的所有数据
        # start_response
    封装要返回给用户的数据响应状态码
       
    start_response('200 ok',[('Content-Type','text/html')])
        #返回的内容
       
    current_url=environ["PATH_INFO"]
        func=None
        if
    current_url in URL_DICT:
            func=URL_DICT[current_url]
        if func:
            return func()
        else:
            return [b'<h1>404</h1>']
    if __name__=="__main__":
        httpd=make_server('',8001,RunServer)
        print("server http on port 8001...")
        httpd.serve_forever()

    s7.py

    from wsgiref.simple_server import make_server
    from Controller import account
    URL_DICT={
        "/index":account.handle_index,
        "/date":account.handle_date,
    }
    def RunServer(environ,start_response):
        # environ 客户发来的所有数据
        # start_response
    封装要返回给用户的数据响应状态码
       
    start_response('200 ok',[('Content-Type','text/html')])
        #返回的内容
       
    current_url=environ["PATH_INFO"]
        func=None
        if
    current_url in URL_DICT:
            func=URL_DICT[current_url]
        if func:
            return func()
        else:
            return [b'<h1>404</h1>']
    if __name__=="__main__":
        httpd=make_server('',8008,RunServer)
        print("server http on port 8008...")
        httpd.serve_forever()

    view-->account.py
    def handle_index():
        import time
        local_time = time.localtime(time.time())
        stime = time.strftime('%Y-%m-%d %H:%M:%S', local_time)
        f=open('view/index.html','rb')
        data=f.read()
        f.close()
        data= data.replace(b'@time', str(stime).encode("utf-8"))
        return [data,]
    def handle_date():
        return [b'<h1>Hello,Date!</h1>']

    Template-->index.py

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <h1>index @time</h1>
    </body>
    </html>
  • 相关阅读:
    HDU 2874 Connections between cities(LCA离线算法实现)
    LCA离线算法Tarjan详解
    HDU 2586 How far away ?(LCA在线算法实现)
    LCA在线算法详解
    LA 4287 等价性证明(强连通分量缩点)
    POJ 2117 Electricity(割点求连通分量)
    ZOJ 1015 Fishing Net(弦图判定)
    BZOJ 1006: [HNOI2008]神奇的国度(弦图染色)
    POJ 2976 Dropping tests(分数规划)
    BZOJ 1003: [ZJOI2006]物流运输(spfa+dp)
  • 原文地址:https://www.cnblogs.com/leiwenbin627/p/10965082.html
Copyright © 2011-2022 走看看