server.py

from wsgiref.simple_server import make_server
from app import application

httpd = make_server('0.0.0.0', 8080, application)
print('start http server 8080...')

httpd.serve_forever()

app.py

def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    print(environ['PATH_INFO'])
    body = '<h1>Hello, %s!</h1>' % (environ['PATH_INFO'][1:] or 'web')
    return [body.encode('utf-8')]

好了,打开浏览器,输入127.0.0.1:8080/helloworld/

注意,server.py运行时可能会卡住,可以反复运行一次,浏览器就能访问到了

相关文章:

  • 2021-12-05
  • 2021-05-04
  • 2021-11-12
  • 2021-11-14
  • 2022-02-28
  • 2021-10-11
  • 2021-06-20
猜你喜欢
  • 2021-04-19
  • 2021-07-07
  • 2021-11-13
  • 2021-09-24
  • 2022-12-23
  • 2021-09-14
相关资源
相似解决方案