zoukankan      html  css  js  c++  java
  • 我的WSGI服务器(带路由功能)

    效果:

    代码:

    from wsgiref.simple_server import make_server


    def teacher(environ,start_response):
    start_response("200 OK",[('Content-Type','text/html;charset=utf-8')])
    return [bytes("<h1>Teacher page</h1>",encoding="utf-8")]

    def student(environ,start_response):
    start_response("200 OK",[('Content-Type','text/html;charset=utf-8')])
    return [bytes("<h1>Student page</h1>",encoding="utf-8")]

    def get_url():
    data= {'/teacher':teacher,'/student':student}
    return data



    def run_server(environ,start_response):
    urls=get_url()
    url=environ.get("PATH_INFO")
    print(url)
    if url in urls:
    function_data = urls[url](environ,start_response)
    return function_data
    else:
    start_response("200 OK",[('Content-Type','text/html;charset=utf-8')])
    return [bytes("<h1>error page</h1>",encoding="utf-8")]


    server = make_server('localhost',8000,run_server)

    server.serve_forever()
  • 相关阅读:
    govalidators 验证
    go iris框架 获取url的两种方法
    tornado框架
    并发/并行,阻塞/非阻塞,同步/异步
    CSS选择器及优先级
    linux下压力测试命令ab
    asyncio
    linux网络原理及基础设置
    linux命令
    linux简介
  • 原文地址:https://www.cnblogs.com/xiaoyichong/p/10958703.html
Copyright © 2011-2022 走看看