8 ms·
Python Web Programming
- brendn 14y agoInteresting that there's no mention of Tornado [1]. (Disclosure: as a co-author of O'Reilly's Introduction to Tornado, I'm biased in its favor.) I haven't played around with Brubeck [2] yet, but I also hear many great things about it. Needless to say, there are some great Python web servers and frameworks out there that aren't listed on that page. [1] http://www.tornadoweb.org/ http://www.tornadoweb.org/ [2] http://brubeck.io/ http://brubeck.io/ Edit: Added links
- kzahel 14y agoI'm also confused. Tornado is definitely a more compelling web framework. Who doesn't want the ability to have tons and tons and tons of long-lived connections?
- brendn 14y agoThe article itself says, "While this HOWTO tries to give an overview of Python in the web, it cannot always be as up to date as desired. Web development in Python is rapidly moving forward, so the wiki page on Web Programming [1] may be more in sync with recent development." So it may not have been the best resource to present on HN in the first place. [1] http://wiki.python.org/moin/WebProgramming http://wiki.python.org/moin/WebProgramming
- slurgfest 14y agoTornado also locks you in to its server completely. That should not be a problem if you are 100% sure it is what you will be using in the future
- brendn 14y agoTornado relies on its own HTTP server, but its modules for everything from templating to authentication are loosely coupled, so you can take them or leave them. To your point, I'd be curious to see a non-Tornado server that is Tornado compatible on the backend. It could be an interesting project. I would counter, however, that any server choice has its own inertia--changing web servers is hardly ever a simple process.
- DizzyDoo 14y agoA good article, but I don't want the Flask web framework (http://flask.pocoo.org/ http://flask.pocoo.org/) to go unnoticed. I struggled along with Django for a number of months, and since I was just beginning web development I felt like I was fighting the large framework, even to build the simplest app. Upon discovering Flask I found it refreshingly simple, and when I moved on to more complicated applications I found it scaled beyond 'toy' apps. It really is worth a look for any Python developer.
- tjr 14y agoAnyone have experience with Flask vs. CherryPy? I started using CherryPy a few years ago and really liked it, but recently Flask [which looks conceptually similar to CherryPy] seems to be (amongst minimal Python web frameworks) the more hip and popular choice.
- pestaa 14y agoYou can use both of them on the same project. The reason is that CherryPy is primarily a web application server, and Flask is primarily a web framework. (I'm not sure why you would want to do that, because Flask comes with Werkzeug, which is better integrated and I trust its author a bit more.) Also, I've never seen a better documentation than Flask's.
- reinhardt 14y ago> (I'm not sure why you would want to do that, because Flask comes with Werkzeug) Well for one, Cherrypy-the-web-server is actually good enough for production. There is much to be said for the benefits of having the same deployment environment in development and production.
- pestaa 14y agoIf you imply Werkzeug is not production-ready, can you please elaborate why?
- domodomo 14y agoThis reminds me, whatever happened to Turbogears? Are many people using it? I never really hear people mention using it compared to Django. I thought long and hard about the "Should I learn Django or Turbogears" question 3 or four years ago, and went with Django. Back then, Django was not yet the "default" answer.
- lmm 14y agoI'm still using it; don't know if it's even maintained any more, but for my app it works really well.
- OptimusSubprime 14y agoThe TG, Pylons, and Zope guys all joined forces under the Pyramid banner a couple of years ago. There are still people developing in each of those three projects (and I think it's largely still maintained), but the definite trend is to Pyramid itself.
- deleted 14y ago[deleted]
- Kilimanjaro 14y agoBottle.py is the simplest way to start playing with web programming in python. Mix it with Jinja and there you have it, good enough for any personal project. Then you make your way up with Flask and Django. * I wish there was a one-file jinja copycat to make it easier to just drop bottle and jinja and start hacking.
- derelk 14y agoI agree Bottle is simple and has some nice features, but I'm a little wary of the decorator-based "micro"frameworks. In my experience it can lead to strange code structure and it's more difficult to translate into the class-based handlers of larger frameworks. Moreover, I don't think the barrier of entry to use Tornado, for example, is significantly higher than Bottle, and you can use it for any sized project. I realize that is both a server and framework, but truthfully I guess I'm also wary of WSGI on the whole and wouldn't recommend anyone even start down that rabbit hole in this day and age.
- Craiggybear 14y agoI like Python for CGI and still use it. Sometimes its all you need instead of frameworks, but Bottle and Flask are great as well.
- streptomycin 14y agoSeems to me that a better title for this article would be "A history of different ways to use Python in the web" rather than "HOWTO Use Python in the web", since most of the article is spent describing old things that should not be used for new projects.
- LeonidasXIV 14y agoAuthor here: While I agree that part of this guide are indeed outdated and could be worth an update (which I haven't had the time to since some years) I still think the general basics are useful. I saw many people get into web programming without having a slightest clue how HTTP works, sometimes even after coming from PHP.
- davepeck 14y agoIt's worth pointing to Graham Dumpleton's blog [1] -- he seems to be the Python world's web hosting ninja. See the great slide deck [2] from his recent talk on hosting python web apps [3] -- the deck nicely captures the recent state of the world. Apache2 + mod_wsgi in Daemon mode is probably the most common approach (especially for VPSs), although I know several people who prefer nginx + gunicorn + supervisor. Both are sane and stable options at this point. (The python web frameworks themselves all speak WSGI and there are about seventeen million of 'em to choose from.) [1] http://blog.dscpl.com.au/ http://blog.dscpl.com.au/ [2] http://modwsgi.googlecode.com/files/mod_wsgi-pycon-sydney-2011.pdf http://modwsgi.googlecode.com/files/mod_wsgi-pycon-sydney-20... [3] http://www.youtube.com/watch?v=PWIvm-uloMg http://www.youtube.com/watch?v=PWIvm-uloMg
- RossM 14y ago> Most HTTP servers are written in C or C++, so they cannot execute Python code directly – a bridge is needed between the server and the program. Are there any HTTP servers written in Python (rather than modules)? I'm struggling to think of any.
- seanwoods 14y agoCherryPy, Tornado, maybe others...
- RossM 14y agoAh, I thought Tornado was a framework. Will investigate a bit more.
- bdarnell 14y agoIt's both. The server and the framework are to some degree usable independently from one another (via the tornado.wsgi module), but the most interesting features (i.e. all the asynchronous stuff) only work when both are used together. A couple of other pure-python (I think) HTTP servers that haven't come up in this thread yet are twisted and paster.
- SpiderX 14y agoAspen, Rocket, Tornado - granted a lot of these have C modules for speed, but they are Python. There are several others.
- lost-theory 14y agoHere's a newer one, from the pylons team: http://pypi.python.org/pypi/waitress/ http://pypi.python.org/pypi/waitress/
- LeonidasXIV 14y agoYes, the HTTP server which is part of the Python stdlib: SimpleHTTPServer in 2.x and http.server in 3.x.
- jonathansizz 14y agoThis link might help you all out: http://docs.python.org/release/3.1.5/index.html http://docs.python.org/release/3.1.5/index.html or are we going to eventually have every single Python doc page posted to HN? It there's no Python news, that doesn't mean you should post random tutorials instead. This is getting tiresome. Flagged.
- slurgfest 14y agoIf it's not useful to post random tutorials, how much less useful is it to post links to documentation for obscure Python versions which hardly anybody uses? Do you even use Python for anything?
- deleted 14y ago[deleted]
- mistercow 14y agoIt's a real shame that support for Python Server Pages is as rare as it is in the wild, and that we don't see that kind of capability common in other server side languages. I really think that the ability to mix HTML and server code together painlessly is one of the main advantages that PHP still has today. It's the reason I still use it for new projects even though I dislike almost everything about the language itself. If I could just say <?coffeescript like that, my programmer-happiness rating would quadruple instantly.
- pconf 14y agoI'd love to see Python Server Pages as well but not implemented anything like it is in PHP. Mixing View and MVC Controller methods/classes in View pages is simply not a sustainable model. Following the PHP example here would seriously taint Python's potential for webapps. Java's JSP, OTOH, is the reference model for that. One big plus for Python Server Pages is the ability to pre-compile into bytecode. True Python doesn't have near the level of compile-time checking that Java does, but it that could be written into a framework...
- deleted 14y ago[deleted]
- mattdeboard 14y agoGreat timing on this. I'm training a very smart & academically accomplished new dev who's spent the last several years pursuing his PhD in CS, but has no idea about web development (I don't consider that a vice). Fortunately he's one of the awesome, awesome people I can just point at an article and he'll be off and running.
- jwallaceparker 14y agoGreat resource. As a side note, I find it interesting that the Django Book does not contain a chapter on test writing. http://www.djangobook.com/ http://www.djangobook.com/
- F_J_H 14y agoWhat would be extremely useful is an equivalent of Michael Hartl's "Ruby on Rails Tutorial" (http://ruby.railstutorial.org/ruby-on-rails-tutorial-book http://ruby.railstutorial.org/ruby-on-rails-tutorial-book) for one of the more popular Python web frameworks... If someone knows of something similar, please let me know.
- slurgfest 14y agoDid you try Googling "Django tutorial"? https://docs.djangoproject.com/en/dev/intro/tutorial01/ https://docs.djangoproject.com/en/dev/intro/tutorial01/ If you don't like that one, there are even more: https://code.djangoproject.com/wiki/Tutorials https://code.djangoproject.com/wiki/Tutorials
- phzbOx 14y agoWhy is there a link to python's documentation on HN frontpage? I mean, it's not like it's a new release or, wait for it, was anything new. Here are some others: - Python/C API Reference Manual http://docs.python.org/py3k/c-api/ - Higher-order functions and operations on callable objects http://docs.python.org/library/functools.html - Google http://www.google.com
- jefe78 14y agoWhy is something like this being posted? It's been in the docs for ages. Seems like link bait to all the folks drooling over Python lately(of which I am).
- n2dasun 14y agoI know nothing about python web programming, but I'm hoping to get deep into it very soon. I wanted to point out the framework that I'm planning to use, because I hadn't seen it mentioned in this thread yet. http://www.web2py.com/ http://www.web2py.com/