• <bdo id='ssAGf'></bdo><ul id='ssAGf'></ul>
  • <tfoot id='ssAGf'></tfoot>
    <i id='ssAGf'><tr id='ssAGf'><dt id='ssAGf'><q id='ssAGf'><span id='ssAGf'><b id='ssAGf'><form id='ssAGf'><ins id='ssAGf'></ins><ul id='ssAGf'></ul><sub id='ssAGf'></sub></form><legend id='ssAGf'></legend><bdo id='ssAGf'><pre id='ssAGf'><center id='ssAGf'></center></pre></bdo></b><th id='ssAGf'></th></span></q></dt></tr></i><div id='ssAGf'><tfoot id='ssAGf'></tfoot><dl id='ssAGf'><fieldset id='ssAGf'></fieldset></dl></div>
      1. <legend id='ssAGf'><style id='ssAGf'><dir id='ssAGf'><q id='ssAGf'></q></dir></style></legend>

        <small id='ssAGf'></small><noframes id='ssAGf'>

        Python REST(Web 服务)框架的推荐?

        Recommendations of Python REST (web services) framework?(Python REST(Web 服务)框架的推荐?)
          <bdo id='BoFwe'></bdo><ul id='BoFwe'></ul>

              <i id='BoFwe'><tr id='BoFwe'><dt id='BoFwe'><q id='BoFwe'><span id='BoFwe'><b id='BoFwe'><form id='BoFwe'><ins id='BoFwe'></ins><ul id='BoFwe'></ul><sub id='BoFwe'></sub></form><legend id='BoFwe'></legend><bdo id='BoFwe'><pre id='BoFwe'><center id='BoFwe'></center></pre></bdo></b><th id='BoFwe'></th></span></q></dt></tr></i><div id='BoFwe'><tfoot id='BoFwe'></tfoot><dl id='BoFwe'><fieldset id='BoFwe'></fieldset></dl></div>
              <legend id='BoFwe'><style id='BoFwe'><dir id='BoFwe'><q id='BoFwe'></q></dir></style></legend><tfoot id='BoFwe'></tfoot>

                  <tbody id='BoFwe'></tbody>
              1. <small id='BoFwe'></small><noframes id='BoFwe'>

                  本文介绍了Python REST(Web 服务)框架的推荐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否有不同的基于 Python 的 REST 框架的建议列表,可用于在服务器端编写您自己的 RESTful API?最好各有优劣.

                  Is there a list somewhere of recommendations of different Python-based REST frameworks for use on the serverside to write your own RESTful APIs? Preferably with pros and cons.

                  请随时在此处添加建议.:)

                  Please feel free to add recommendations here. :)

                  推荐答案

                  在设计 RESTful API 时需要注意的是 GET 和 POST 的混淆,就好像它们是同一个东西一样.Django 的 基于函数的视图 和 CherryPy 的默认调度程序,尽管两个框架现在都提供了解决此问题的方法 (基于类的视图 和 MethodDispatcher,分别).

                  Something to be careful about when designing a RESTful API is the conflation of GET and POST, as if they were the same thing. It's easy to make this mistake with Django's function-based views and CherryPy's default dispatcher, although both frameworks now provide a way around this problem (class-based views and MethodDispatcher, respectively).

                  HTTP 动词在 REST 中非常重要,除非你非常小心关于这一点,你最终会陷入 REST 反模式.

                  HTTP-verbs are very important in REST, and unless you're very careful about this, you'll end up falling into a REST anti-pattern.

                  一些正确的框架是 web.py、Flask 和 瓶.当与 mimerender 库(完全公开:我写的)结合使用时,它们允许您编写漂亮的 RESTful Web 服务:

                  Some frameworks that get it right are web.py, Flask and Bottle. When combined with the mimerender library (full disclosure: I wrote it), they allow you to write nice RESTful webservices:

                  import web
                  import json
                  from mimerender import mimerender
                  
                  render_xml = lambda message: '<message>%s</message>'%message
                  render_json = lambda **args: json.dumps(args)
                  render_html = lambda message: '<html><body>%s</body></html>'%message
                  render_txt = lambda message: message
                  
                  urls = (
                      '/(.*)', 'greet'
                  )
                  app = web.application(urls, globals())
                  
                  class greet:
                      @mimerender(
                          default = 'html',
                          html = render_html,
                          xml  = render_xml,
                          json = render_json,
                          txt  = render_txt
                      )
                      def GET(self, name):
                          if not name: 
                              name = 'world'
                          return {'message': 'Hello, ' + name + '!'}
                  
                  if __name__ == "__main__":
                      app.run()
                  

                  服务的逻辑只实现一次,正确的表示选择(Accept header)+派发到适当的渲染函数(或模板)以整洁、透明的方式完成.

                  The service's logic is implemented only once, and the correct representation selection (Accept header) + dispatch to the proper render function (or template) is done in a tidy, transparent way.

                  $ curl localhost:8080/x
                  <html><body>Hello, x!</body></html>
                  
                  $ curl -H "Accept: application/html" localhost:8080/x
                  <html><body>Hello, x!</body></html>
                  
                  $ curl -H "Accept: application/xml" localhost:8080/x
                  <message>Hello, x!</message>
                  
                  $ curl -H "Accept: application/json" localhost:8080/x
                  {'message':'Hello, x!'}
                  
                  $ curl -H "Accept: text/plain" localhost:8080/x
                  Hello, x!
                  

                  更新(2012 年 4 月):添加了有关 Django 的基于类的视图、CherryPy 的 MethodDispatcher 以及 Flask 和 Bottle 框架的信息.提出问题时两者都不存在.

                  Update (April 2012): added information about Django's class-based views, CherryPy's MethodDispatcher and Flask and Bottle frameworks. Neither existed back when the question was asked.

                  这篇关于Python REST(Web 服务)框架的推荐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)
                    <tbody id='C5dcj'></tbody>

                    <legend id='C5dcj'><style id='C5dcj'><dir id='C5dcj'><q id='C5dcj'></q></dir></style></legend>

                      <tfoot id='C5dcj'></tfoot>
                      <i id='C5dcj'><tr id='C5dcj'><dt id='C5dcj'><q id='C5dcj'><span id='C5dcj'><b id='C5dcj'><form id='C5dcj'><ins id='C5dcj'></ins><ul id='C5dcj'></ul><sub id='C5dcj'></sub></form><legend id='C5dcj'></legend><bdo id='C5dcj'><pre id='C5dcj'><center id='C5dcj'></center></pre></bdo></b><th id='C5dcj'></th></span></q></dt></tr></i><div id='C5dcj'><tfoot id='C5dcj'></tfoot><dl id='C5dcj'><fieldset id='C5dcj'></fieldset></dl></div>
                          <bdo id='C5dcj'></bdo><ul id='C5dcj'></ul>
                          1. <small id='C5dcj'></small><noframes id='C5dcj'>