是否有一份关于在服务器端使用不同基于python的REST框架来编写自己的RESTful api的推荐列表?最好有正反两面。

请随意在这里添加建议。:)


当前回答

我不是python世界的专家,但我一直在使用django,这是一个优秀的web框架,可以用来创建一个restful框架。

其他回答

我真的很喜欢樱桃皮。下面是一个基于rest的web服务的例子:

import cherrypy
from cherrypy import expose

class Converter:
    @expose
    def index(self):
        return "Hello World!"

    @expose
    def fahr_to_celc(self, degrees):
        temp = (float(degrees) - 32) * 5 / 9
        return "%.01f" % temp

    @expose
    def celc_to_fahr(self, degrees):
        temp = float(degrees) * 9 / 5 + 32
        return "%.01f" % temp

cherrypy.quickstart(Converter())

这强调了我真正喜欢CherryPy的地方;这是一个完全可行的例子,即使对不了解框架的人来说也是可以理解的。如果你运行这段代码,你可以立即在浏览器中看到结果;例如,访问http://localhost:8080/celc_to_fahr?degrees=50将在您的web浏览器中显示122.0。

2010年,塔和repoze。bfg社区“联合起来”创建了Pyramid,这是一个基于repoze.bfg的web框架。它保留了其父框架的理念,可用于基于rest的服务。值得一看。

请参阅Python Web Frameworks wiki。

您可能不需要完整的堆栈框架,但剩下的列表仍然相当长。

没想到居然没人提到烧瓶。

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

我不是python世界的专家,但我一直在使用django,这是一个优秀的web框架,可以用来创建一个restful框架。