简体   繁体   English

哪个python网络框架可轻松进行开发和部署?

[英]Which python web framework has hassle-free development and deployment?

I have written a web API in BaseHTTPServer. 我已经在BaseHTTPServer中编写了一个Web API。 It is meant to be used only on localhost. 它只能在localhost上使用。 It returns JSON objects on GET/POST operations. 它在GET / POST操作上返回JSON对象。

http://localhost:8888/operation?param

and code is like 和代码就像

def do_GET(self):
   if self.path=="operation":
       self.wfile.write("output")

But I am worried about keep-alive mechanisms (read: a webserver that can respawn workers), lack of multi-threading, and PITA-ful maintenance. 但是我担心保持活动的机制(请参阅:可以重新生成工作程序的Web服务器),缺乏多线程和PITA高效维护。


And like I said, I am looking at the development and deployment issues for choosing this web framework. 就像我说的那样,我正在研究选择此Web框架的开发部署问题。

Development 发展

The web interface is currently 250 lines and has very simple features. Web界面当前为250行,并且功能非常简单。 I am looking for something that lends itself well to clean maintenance and deployment. 我正在寻找能很好地进行清洁维护和部署的东西。 I dont want the framework's MVC, ORM, templating and other features messing my learning curve. 我不希望框架的MVC,ORM,模板和其他功能弄乱了我的学习曲线。 UrL patterns that redirect to appropriate module is nice. 重定向到适当模块的UrL模式很好。

Deployment 部署

It should deploy on a mature server with a WSGI module with minimum fuss. 它应该部署在具有WSGI模块的成熟服务器上,并尽量减少麻烦。 And such a setup has hot-deploy (for want of a better word), installing a new application or updating the code means copying the files to the www-root in the filesystem. 这样的设置具有热部署功能 (需要一个更好的词),安装新应用程序或更新代码意味着将文件复制到文件系统中的www-root。


CherryPy and Flask seem interesting. CherryPy和Flask似乎很有趣。 Django and Web2Py seem too comprehensive. Django和Web2Py似乎过于全面。

The recommended way of deploying wsgi is as a long-running-process , either embedded or daeomonized, and not as a cgi script. 推荐的wsgi部署方式是作为长期运行的进程 (嵌入式或daeomonized),而不是cgi脚本。 Either way, its going to be a little different than just uploading files like in php, restarting the server/process by touching the config file is normally the closest you get to "hot-deployment" using wsgi. 无论哪种方式,其效果都与仅上传文件(如在php中)有所不同,通过触摸配置文件重新启动服务器/进程通常是使用wsgi最接近“热部署”的方式。

Needless to say, the framework itself does not impose any kind of deployment restraints if it is wsgi compliant. 不用说,如果框架符合wsgi,则框架本身不会施加任何类型的部署约束。 Take your pick depending on your needs: apache+modwsgi, gunicorn, cherry.py, paste. 根据您的需要选择:apache + modwsgi,gunicorn,cherry.py,粘贴。 None of them offer "hot-deployment" (afaik), you will still need to create a wsgi script and reload the processes. 它们都不提供“热部署”(afaik),您仍然需要创建wsgi脚本并重新加载进程。 The filesystem layout is normally of no concern and that's good. 文件系统布局通常是无关紧要的,这很好。 You don't usually get autoreload either. 您通常也不会自动重载。 I know werkzeug and cherry.py do, and werkzeug offers some really cool debugging tools too. 我知道werkzeug和cherry.py都可以,而且werkzeug也提供了一些非常酷的调试工具。 Please note that tornado/werkzeug* itself offers an autoreload option, but is actually considered for development and not deployment, and not compatible with the wsgi module. 请注意,tornado / werkzeug *本身提供了一个自动重装选项,但实际上考虑用于开发而不是部署,并且与wsgi模块不兼容

But no matter how painful or painless the deployment is, it is recommended to use something like fabric to automate your deployments, and setting up a wsgi web server isnt that that hard. 但是,无论部署有多痛苦或无痛苦,都建议使用诸如Fabric之类的东西来自动化您的部署,并且设置一个wsgi Web服务器并不那么困难。

Choice of the framework itself is kind of tricky, and depends on what level you want to work in. Tornado, werkzeug are popular low level frameworks, (but also include higher level tools, and many are frameworks+webserver), but you could also work with webob directly and just plugin whatever else you need. 框架本身的选择有些棘手,取决于您要使用的级别。Tornado,werkzeug是流行的低级框架(但也包括较高级的工具,其中许多是框架+网络服务器),但是您也可以直接与webob合作 ,只需插入其他所需的插件即可。

You have the microframeworks like flask or bottle, then the lightweight frameworks, like web2.py, or maybe pyramid (the lines on how heavy a framework are kind of blurry). 您拥有诸如长颈瓶或瓶子的微框架,然后是轻量级框架,例如web2.py或金字塔(关于框架有多沉重的线条有些模糊)。

Then you have the "full-stack" django, grok, turbogears, etc... And then you have zope, which has been on a diet but still very heavy. 然后,您将拥有“全栈式”的django,grok,turbogears等。然后,您将获得zope,该食品一直在节食,但仍然非常沉重。

Note that you can pretty much do anything with all of them (just depends how much you want to bend them), and in many cases you can swap components rather easily. 请注意,几乎所有组件都可以执行任何操作(仅取决于要弯曲它们的程度),并且在许多情况下,可以很容易地交换组件。 I'd start try out a microframework like bottle or maybe flask (you don't have to use ORM's or templating, but are easily available once you do), but also take a look at webob . 我将开始尝试使用诸如酒瓶保温瓶之类的微框架(您不必使用ORM或模板,但一旦使用就可以轻松使用),还可以看看webob

*comment: added werkzeug to the not really autoreload camp. *评论:将werkzeug添加到了不是真正的自动重装阵营中。

For what you describe, id go with: Tornado Web Server 对于您所描述的内容,id与: Tornado Web Server

This is the hello world: 这是你好世界:

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

It's highly scalable, and I think it may take you 10 minutes to set it up with your code. 它具有高度的可扩展性,我认为您可能需要10分钟来设置代码。

I personally like and use web.py all the time. 我个人一直很喜欢并使用web.py。 It's very lightweight and customizable and WSGI compliant. 它非常轻巧,可定制且符合WSGI。

http://webpy.org http://webpy.org

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Scala/Java 中类似于 Python 的 Pickle 的简单、轻松、零样板序列化? - Simple, hassle-free, zero-boilerplate serialization in Scala/Java similar to Python's Pickle? 什么是通过短期运行流程管理内容并获得输出的最轻松的方法? - What's the most hassle-free way to pipe stuff through a short-running process and get output? Python Web项目的剖析:开发,打包,部署 - The anatomy of a Python web project: development, packaging, deployment 用于python 3.1用户的Python Web开发框架 - Python web development framework for python 3.1 user 我需要一个很好的Python Web开发框架 - I need a good web development framework for Python 什么是用螺丝钉的Python编组修复virtualenv的最快,最轻松的方式? - What's the quickest, most hassle free way of fixing a virtualenv with screwy python marshalling? 哪个轻量级python Web框架具有应用程序和热部署的代码 - Which lightweight python web framework has applications and hot-deployed code 如何在不依赖框架的情况下使用python进行Web开发? - How do I use python for web development without relying on a framework? 什么Python / IronPython Web开发框架可以在Microsoft技术堆栈上运行? - What Python/IronPython web development framework work on the Microsoft technology stack? 我应该使用哪个版本的Python进行Web开发? - Which version of Python should I use for web development?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM