zoukankan      html  css  js  c++  java
  • python 练习 后台返回当前时间

    新建一个 current_time.html 文件, !cur_time! 用来替换

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <h1>current_time: !cur_time!</h1>
    </body>
    </html>
    

    新建一个 server.py 文件

    from wsgiref.simple_server import make_server
    import time
    
    def current_time(request):
        cur_time = time.ctime(time.time())
        f=open("current_time.html","rb")
        data=f.read()
    
        # 替换当前的时间
        data=str(data,"utf8").replace("!cur_time!",str(cur_time))
    
        return [data.encode("utf8")]
    
    def routers():
        urlpatterns = (
            ('/cur_time', current_time),
        )
        return  urlpatterns
    
    def application(environ, start_response):
        start_response('200 OK', [('Content-Type', 'text/html')])
    
        urlpatterns = routers()
        path = environ["PATH_INFO"]
        func = None
        for item in urlpatterns:
            if item[0] == path:
                func = item[1]
                break
        if func:
            return func(environ)
        else:
            return ["<h1>404</h1>".encode("utf8")]
    
    
    
    httpd = make_server('', 8888, application)
    
    print('Serving HTTP on port 8888...')
    httpd.serve_forever()
    
    
  • 相关阅读:
    第一章 jQuery基础方法回顾
    php无法执行python
    echarts
    logstash配置
    storm结合kafka
    spark中读取elasticsearch数据
    hadoop中读取protobuf数据
    spark1.3.1配置模板
    hadoop2.6.0配置模板
    使用jnetpcap捕获数据包进行流量检测
  • 原文地址:https://www.cnblogs.com/klvchen/p/10600320.html
Copyright © 2011-2022 走看看