simple_server 搭建简易后端服务

from wsgiref.simple_server import make_server


def app(env, start_response):
    # env代表本地环境变量,dict类型
    # {'PATH': '/Users/jt/python_env/flask_demo/venv/bin,'MANPATH': '/opt/homebrew/share/man::',
    # 'WORKON_HOME': '/Users/jeanettian/python_env'}
    # print(env)
    print(env.get('PATH_INFO'))
    if env.get('PATH_INFO') == '/login':
        start_response('200 ok', [('content-type', 'text/plain')])
        return [b'this is login view']  # b:byte
    elif env.get('PATH_INFO') == '/register':
        start_response('200 ok', [('content-type', 'text/plain')])
        return [b'his is register view']  # b:byte
    elif env.get('PATH_INFO') == '/index':
        start_response('200 ok', [('content-type', 'text/plain')])
        return [b'his is index view']  # b:byte
    elif env.get('PATH_INFO') == '':
        start_response('200 ok', [('content-type', 'text/plain')])
        return [b'{name: chuntian!,age:4}']  # b:byte
    else:
        start_response('404 not found', [('content-type', 'text/plain')])
        return [b'404 page not found']  # b:byte


server = make_server('', 5001, app=app)
# 启动服务
server.serve_forever()

1.浏览器访问login时:

simple_server 搭建简易后端服务

 2.浏览器访问register时:

simple_server 搭建简易后端服务

 

3.浏览器访问index时:

simple_server 搭建简易后端服务

 

4.浏览器访问' /'时:

simple_server 搭建简易后端服务

5.浏览器访问不存在的路由时:

simple_server 搭建简易后端服务

 

上一篇:jQuery Moblie 学习(一)


下一篇:Orcla 数据库复习2 --子查询和表连接