0

我正在寻找 python 中的简单回显服务器实现。我用谷歌搜索了它,但所有结果都依赖于外部库。我正在从 html 向 python 发送一个字符串:

$.post("server.py", 'blabla')

我希望python做的是这样的:

wait for request:
    send_back('OK: ' + uppercase(request.data))

你怎么做到这一点?

4

1 回答 1

1

您需要一些东西来处理您的 URL。你试过Web.py

它可以让您快速入门。

import web

urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello:        
    def GET(self, name):
        if not name: 
            name = 'World'
        return 'Hello, ' + name + '!'

if __name__ == "__main__":
    app.run()
于 2013-08-22T06:40:23.580 回答