How to implement a minimal server for AJAX in Python?

前端 未结 4 1978
既然无缘
既然无缘 2020-11-27 09:45

I want to create a very simple HTML/AJAX based GUI for a Python program. So the frontend is a HTML page which communicates with the program via AJAX. Can you give me a minim

4条回答
  •  温柔的废话
    2020-11-27 10:08

    Use the WSGI reference implementation. In the long run, you'll be happier.

    from wsgiref.simple_server import make_server, demo_app
    
    httpd = make_server('', 8000, demo_app)
    print "Serving HTTP on port 8000..."
    
    # Respond to requests until process is killed
    httpd.serve_forever()
    

    The demo_app is relatively easy to write; it handles your Ajax requests.

提交回复
热议问题