TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Best Python web framework

116 点作者 benohear大约 13 年前
I know this question gets asked every now and again, but the most recent informed thread I found was two years old and, as we all know, things move on.<p>Last time, the answer could be summarized as "Django but ...", with Pylons and Flask getting a good mention. Have these now "overtaken" the incumbent? What about Web2Py?

29 条评论

idan大约 13 年前
(Full disclosure: I'm a member of Django's core team)<p>There's no single "best" for every application. One-size-fits-none. One of Django's strengths is in the fact that parts of the framework come off easily when they no longer serve your needs. If the ORM is no longer working for you, you can use SQLAlchemy or write raw SQL. Authentication no longer working for you? Write your own or use a 3rd party one.<p>Et cetera. The key aspect is that you don't need to sacrifice the entire framework when only one part of it no longer addresses your needs. Keep in mind that 99% of sites never even reach this point.<p>The other major strength of django is the rich ecosystem of 3rd party apps. That's a lot of code you don't need to write yourself.<p>That being said, Flask is popular for a reason. Django offers a lot of power, which means adding some complexity to even the simplest projects (something we're working to address with features like project templates in Django 1.4). Flask fills a niche for a framework that is easy to get up and running and addresses 90% of the things which 90% of people need for many projects.<p>I've heard good things about pyramid, but haven't had a chance to play yet.<p>I haven't had the "pleasure" of working with web2py, and I'm not knocking the effort which Massimo puts into it, but the choices made there often elicit a raised eyebrow. Ignoring my opinion for a moment, the smartest web hackers I know universally regard web2py as a fundamentally incorrect way to approach web development—but usually say so in far more colorful terms.<p>TL;DR<p>* Flask for simpler stuff<p>* Django for anything larger, or simple stuff that leverages a 3rd-party app you need.<p>* What matters is the app you ship, not the framework it was built with.<p>* Django developers are in super-high demand. I get cold-called frequently.
评论 #3765825 未加载
评论 #3766295 未加载
评论 #3765946 未加载
评论 #3765867 未加载
评论 #3766461 未加载
评论 #3767009 未加载
评论 #3767553 未加载
评论 #3765828 未加载
评论 #3777810 未加载
评论 #3767091 未加载
评论 #3777648 未加载
peter_l_downs大约 13 年前
I really like bottle.py [1]. I've used it for a couple of different projects; although not fundamentally different from web.py or flask, it seems to just "make sense".<p>[1] <a href="http://bottlepy.org/docs/stable/" rel="nofollow">http://bottlepy.org/docs/stable/</a><p>An example from their website:<p><pre><code> from bottle import get, post, request @get('/login') # or @route('/login') def login_form(): return '''&#60;form method="POST"&#62; &#60;input name="name" type="text" /&#62; &#60;input name="password" type="password" /&#62; &#60;/form&#62;''' @post('/login') # or @route('/login', method='POST') def login_submit(): name = request.forms.get('name') password = request.forms.get('password') if check_login(name, password): return "&#60;p&#62;Your login was correct&#60;/p&#62;" else: return "&#60;p&#62;Login failed&#60;/p&#62;"</code></pre>
评论 #3765886 未加载
评论 #3765840 未加载
j2labs大约 13 年前
Try Brubeck. It's a Python web framework built around Gevent, DictShield and ZeroMQ. It communicates with Mongrel2, it's web server, via ZeroMQ sockets so even the annoying design of WSGI is moved out of the way.<p>It converts your blocking calls to nonblocking, has no spaghetti code filled with callback shenanigans, and can even generate a full REST API for you.<p><a href="https://github.com/j2labs/brubeck" rel="nofollow">https://github.com/j2labs/brubeck</a>
评论 #3766546 未加载
评论 #3766679 未加载
espeed大约 13 年前
Flask is at about the right level of abstraction in the age of polyglot DBs and the JS movement to put the presentation in the browser. Flask gets out of your way and makes it easy to adapt to the changing environment without having to hack your way out of a monolith.<p>Diesel (<a href="http://diesel.io/" rel="nofollow">http://diesel.io/</a>) has piqued my interest as of late -- it's a high-concurrency, coroutine-based framework with Flask under the hood, by the guys at Bump.<p>The next-gen Python Web frameworks will probably be non-WSGI because WSGI doesn't support WebSockets.<p>One approach would be a ZeroMQ-based framework like Brubeck (<a href="http://brubeck.io/" rel="nofollow">http://brubeck.io/</a>) behind Mongrel2 (<a href="http://mongrel2.org/" rel="nofollow">http://mongrel2.org/</a>). But AFAIK, WebSocket support is not yet fully baked into Mongrel2. The handshake still needs to happen on the handler side.
inovica大约 13 年前
The best for what? What do you want to do?<p>We have found Django to be great for throwing up a site quickly. We primarily use Pyramid now for our more serious development as it fits more with what we're trying to achieve. My feeling is the beauty of Python is that there are more than one ways of doing something. Define what you want out of your framework, try some and then see how you feel
评论 #3765695 未加载
评论 #3765727 未加载
beagle3大约 13 年前
web2py is great. Really. I'm quite sure some people are confusing web.py (toolkit behind reddit) and web2py - I know I was a couple of years ago.<p>web2py is super complete, but doesn't get in your way, and doesn't require you to learn everything up front. It's DAL is much simpler (and in my opinion, much more effective) than an ORM -- but you don't have to use it.<p>Its templating system is just plain python inside {{}}, where you need to add "pass:" to dedent if it cannot be inferred from the code, but that's it. No need to learn a new templating system.<p>The community is super awesome. Starter applications like issue trackers, minimal facebooks or twitters etc. are often posted on the mailing list inside one short message (not as an attachment -- the whole thing is posted inside the message text, and takes no more than two screenfuls)<p>Really, give web2py a try if you haven't.
评论 #3766488 未加载
评论 #3766489 未加载
AnthonyB3大约 13 年前
Well, according to InfoWorld, web2py is the best Python framework (<a href="http://www.infoworld.com/d/application-development/pillars-python-six-python-web-frameworks-compared-169442" rel="nofollow">http://www.infoworld.com/d/application-development/pillars-p...</a>). It also won a 2011 Bossie Award for open source development software (<a href="http://www.infoworld.com/d/application-development/pillars-python-six-python-web-frameworks-compared-169442" rel="nofollow">http://www.infoworld.com/d/application-development/pillars-p...</a>) and a 2012 Technology of the Year Award (<a href="http://www.infoworld.com/slideshow/24605/infoworlds-2012-technology-of-the-year-award-winners-183313" rel="nofollow">http://www.infoworld.com/slideshow/24605/infoworlds-2012-tec...</a>).<p>Don't listen to the naysayers about web2py -- it is rare to find one who has actually ever used it. Meanwhile, web2py has a large, active, and steadily growing base of <i>real</i> users who are very happy and doing just fine producing and maintaining web applications with it. In fact, many web2py users are former Django users who simply find web2py more productive (see <a href="http://www.quora.com/What-are-the-advantages-of-web2py-over-Django/answer/Anthony-Bastardi" rel="nofollow">http://www.quora.com/What-are-the-advantages-of-web2py-over-...</a>).<p>Note, most of the criticisms of web2py have all the earmarks of FUD (<a href="http://en.wikipedia.org/wiki/Fear,_uncertainty_and_doubt" rel="nofollow">http://en.wikipedia.org/wiki/Fear,_uncertainty_and_doubt</a>) -- lots of references to authority and calls to stick with a perceived standard way of doing things, but not much discussion of actual technical merits nor presentation of any empirical evidence to back up the strong claims being made (see <a href="http://www.quora.com/Is-web2py-a-good-Python-web-framework/answer/Anthony-Bastardi" rel="nofollow">http://www.quora.com/Is-web2py-a-good-Python-web-framework/a...</a>). Some of the critics seem overly concerned with the notions of "explicitness" and "magic", but not everyone shares their concerns: <a href="https://twitter.com/#!/zedshaw/status/80418794526351360" rel="nofollow">https://twitter.com/#!/zedshaw/status/80418794526351360</a>.
sontek大约 13 年前
Pyramid is probably the best at the moment. It has a lot of power when it comes to fine grained security utilizing access control lists and it integrates really well with the major python libraries out there.
iso8859-1大约 13 年前
CherryPy has had Python 3 support for quite a while now. Not many Python frameworks have that. Pylons just got it, so I'd go with CherryPy. You can get WebSocket support too, and documentation is OK.
评论 #3766136 未加载
评论 #3765887 未加载
ruxkor大约 13 年前
I'm surprised nobody mentioned brubeck (<a href="http://brubeck.io" rel="nofollow">http://brubeck.io</a>) until now, which takes a completely fresh approach to concurrent handling via implicit context switching (more on their website).<p>Obviously, as idan mentioned already, there is no single "best" framework, so it really depends on the type of application you want to build whether you should choose something like bottle/flask, django/mezzanine/pinax or brubeck/tornado, or even twisted.
lucian1900大约 13 年前
Sadly, Django is still by far the most popular. It's ok, though. You're likely to not hate it intensely. It also has a lot of third party code available, and a fair amount of functionality built-in.<p>Flask is nicer (and lets you seamlessly use SQLAlchemy, which is so much better than Django's crappy ORM), but also tiny. It's basically just a bit of glue between werkzeug, SQLAlchemy and Jinja2.<p>Pyramid has more things in it than Flask and also uses SQLAlchemy.<p>web2py appears both bad and unpopular to me.
评论 #3769246 未加载
评论 #3766332 未加载
评论 #3765945 未加载
评论 #3766336 未加载
评论 #3769248 未加载
评论 #3769247 未加载
esonderegger大约 13 年前
I've been using Flask for my current project and I absolutely love it.<p>The project is a web interface for our library's digital archives (mostly audio and video assets, but also images and print documents). Version 1 of the project used php and mysql for the front end with python scripts handling the transcoding and metadata handling on the back end. For a variety of reasons the project got bloated to the point of being unmanageable. I decided I wanted a fresh start with a python framework and considered all the ones mentioned here.<p>I went with Flask because I wanted to leave the existing database structure in place and I wanted to err on the side of the framework doing too little instead of too much.<p>As a non-programmer (my job title says "audio engineer"), Flask was simple enough to understand, but did enough to make my life considerably easier. My one gripe is I think Flask-Login still has room for improvement, at least in terms of documentation. I've gotten it working good enough, but I still don't understand how credentials are passed around my application.<p>I'm sure other frameworks would have also gotten me to where I needed to be, but after working with Flask for a month or so, I'm not immediately reaching for something else.
tzury大约 13 年前
Tornado.<p>Built-in async operations.<p>Not standing in your way.<p>Rapid developments.<p>Huge community.<p>Simply works.<p>Simple, yet rich.
评论 #3766140 未加载
评论 #3765851 未加载
评论 #3766431 未加载
dcESC大约 13 年前
Pylons is now called pyramid. I don't know how much it changed?<p>I prefer pylons above Django. Simply because it feels less like a framework.
评论 #3765846 未加载
glimmung大约 13 年前
Depends on what you are developing, of course.<p>I picked web2py about 3 years ago, and it has worked well for me. I'm developing CRUD apps to solve business problems with the minimum of fuss and effort, but with the confidence that I can roll my sleeves up and exercise more control if I need to - web2py has been a good fit for that.
nashad大约 13 年前
I built a couple of web.py apps and here are my observations:<p>-- Advantages --<p>* Minimal configuration (No configuration file, just run a single python file in the simplest case)<p>* Getting started is really fast<p>* import whatever libraries you like (PyMongo, SqlAlchemy, Mako, Beaker, etc) - No lock in<p>* The Web.py source is straightforward enough that you can go directly there to figure stuff out<p>* WSGI compatible<p>* No Admin interface and extra scaffolding<p>* Very simple URL routing interface<p>* Simple cookbook is available for adding basic features<p>-- Disadvantages --<p>* Smaller community<p>* Not a lot of documentation or guides<p>* Some problems will require you to look at the source<p>* No built in user management/auth<p>* Web.py development community isn't adding new features rapidly<p>--Conclusion--<p>Probably good for rapidly building simple web apps. It seems like the support/infrastructure needed for a large-scale production app isn't available. However if you are willing to build out your components it will give you maximum flexibility for a larger app
drahcir大约 13 年前
I have used web2py for the last few years and have been happy with it:<p>- well designed components: DAL, SQLFORM, views, etc<p>- commitment to backwards compatibility<p>- works on GAE<p>- helpful community (groups.google.com/group/web2py)<p>- thorough documentation (web2py.com/book)<p>The main criticism of web2py is that its design is not 'pythonic', which is irrelevant to me.
aaronsnow大约 13 年前
Richard Jones did a nice presentation about this in August 2011, comparing 10 Python frameworks along a lot of useful metrics (perf, simplicity, size, documentation, etc) by developing the same "hello world"-ish app in each one. He even scored them at the end.<p>The slides are at <a href="http://www.slideshare.net/r1chardj0n3s/web-microframework-battle" rel="nofollow">http://www.slideshare.net/r1chardj0n3s/web-microframework-ba...</a> -- they don't seem to be loading inline now but the PDF download still works. Video of the talk is at <a href="http://www.youtube.com/watch?v=AYjPIMe0BhA" rel="nofollow">http://www.youtube.com/watch?v=AYjPIMe0BhA</a> .<p>Spoiler alert: the winner was bottle.py, by a nose.
评论 #3766530 未加载
评论 #3766558 未加载
zengyro大约 13 年前
I use web2py. It struggles to get the attention that Django gets, but it has a robust development community.<p>It offers a good balance between Django (which i find a little big and unwieldy), and Flask (which I think suffers from the opposite problem).
评论 #3765790 未加载
kung-fu-master大约 13 年前
Flask is best IMHO. Django is good enough.
gbog大约 13 年前
As with whichever framework you choose you will have to get inside its code to understand it, adapt to it or fix it, I would advise to choose one framework that has code that is pleasing to read and follow very strictly conventions. Right now my box is broken so I can't check but last I have checked Django had a relatively good pylint score, while Flask had a seemingly slightly more messy code base.
calibwam大约 13 年前
Depends on what you want from the framework. Django is good, but for a smaller blog, try pyblosxom, it's quite nice!
abdulhaq大约 13 年前
Here's a vote for cherrypy - it handles all the http / protocol shenanigans for you, but leaves the meaty business side entirely to you - which, as an experienced developer, is what I want.
edwinyzh大约 13 年前
I've ten years of Delphi background. I'll choose Flask, because it's simple - I immediately learned how it works, and it's neat.
magnusmorton大约 13 年前
Which (or do any) of the major Python frameworks have Python 3 support?
评论 #3766042 未加载
wyuenho大约 13 年前
BlueberryPy author here. Allow me to plug CherryPy and my micro-framework built on top of CherryPy called BlueberryPy.<p>Here's my answer on stackoverflow early last year when someone asked for a CherryPy vs Flask comparison. I believe all the points still stand and still represent CherryPy's strengths.<p>1. Simplicity. Controller object trees more or less equal to how you would define your URLs. 2. Flexibility. In case you don't like how the URLs are defined by default, you can use routes or methods to expose your URL handlers, which are just as easy. 3. Tools. CherryPy isn't religious about WSGI, though it's 100% compatible with the WSGI spec, the recommended approach is to use Tools. They are simple to make and use, and the way they are wired to the request is a lot more efficient than WSGI, which typically a request has to pass through whether or not that particular WSGI middleware is relevant. (Unless you use a framework where each URL handler is a WSGI application, but wiring up WSGI apps are still annoying). There are <i></i>LOTS<i></i> of them supplied by default that cover most of the use cases you can think of. 4. Plugins. For cross-cutting concerns, engine plugins are a much more granular, well-defined, and suitable way to deal with them as opposed to a WSGI app, which is typically the hammer people use to hammer in every screw these days. 5. Easy chunked responses. You just yield a string in the controller and that's it. Very useful for returning large documents in pieces. 6. Full-featured request and response objects. WebOb and CherryPy are about the only 2 frameworks that have comparably complete implementations of them, but I'd still choose CherryPy for the last reason: 7. Zero dependency on other packages. You won't bring in a dozen other libraries just to run a server. You just easy_install or pip install cherrypy and that's it.<p>Its WSGI server is also the canonical choice if you need a fast and stable pure Python WSGI server implementation. It's actually really really fast and stable:<p><pre><code> http://nichol.as/benchmark-of-python-web-servers </code></pre> Now, I've been using CherryPy for about 5 years now and am still absolutely in love with it. I love it so much that I've decided last month to open source the micro-framework I've built on top of CherryPy called BlueberryPy:<p><pre><code> https://bitbucket.org/wyuenho/blueberrypy </code></pre> It's basically a set of additional tools and plugins for CherryPy which give you an easier integration with SQLAlchemy, logging, Redis and Jinja2, webassets and various other goodies. It also comes with a project skeleton generator akin to many other frameworks out there but doesn't get in your way with the generated source files. All that BlueberryPy asks for is a configuration directory with a few correct YAML config files with a few keys pointing to a few classes in your package. Documentation is a little light but more will come soon enough as I find time to finish them up. Stay tuned :P
intellectronica大约 13 年前
web.py
评论 #3765943 未加载
blye_kzn大约 13 年前
web2py : others :: python : others<p>web2py : dj<i></i><i></i>* :: python : java
illumen大约 13 年前
Pyramid.<p><a href="http://en.wikipedia.org/wiki/Pyramid_%28web_framework%29" rel="nofollow">http://en.wikipedia.org/wiki/Pyramid_%28web_framework%29</a><p>* faster.<p>* better quality (100% statement coverage via unit tests)<p>* supports latest python.<p>* great documentation (including free up to date book). There's also a separate pyramid cookbook.<p>* simplicity. If you just see a pyramid app, you can dive right in fairly easily without learning lots of alien stuff.<p>* sensible defaults, and you can choose to swap out parts easily if you want (templates, ORM, etc).<p>* works well with other python software, doesn't bundle everything in, with NIH syndrome.<p>* great tools. like the web console that drops straight into a debugger when an exception happens on the page you're looking at.<p>The framework that starts with D is a legacy framework (doesn't even support python3 yet).
评论 #3765954 未加载