Some years ago, I was looking for forum software, preferably written in Python, so I found Pocoo’s original bulletin board project. Since then, I’ve kept an eye on the Pocoo team, experimenting early on with Werkzeug, and using Pygments (indirectly) and Sphinx (for the documentation of the Pyrseas project). I also heard about Jinja but, I guess because I was already invested in Mako Templates, wasn’t much interested in a Django Templates lookalike.
Fast forward to the present and this database user interfaces tutorial and project. My next step was going to replace my dinky WSGI “server” and associated routing code by a robust and substantial alternative. I was almost set on using CherryPy, but had some doubts.
CherryPy is a solid WSGI server framework. I chose it on previous projects, over others such as Zope, Django, TurboGears and Pylons, primarily because it’s relatively lightweight and, as they say, “agnostic.” CP doesn’t include nor even suggest its own template language, ORM or database layer, or JavaScript library. The one thing that may take some getting used is its URI mapping scheme.
In spite of the above, I thought that CherryPy was perhaps too heavy a dependency to add to the project and particularly to this tutorial. So I kept my eyes and ears open to alternatives.
About a month ago, I briefly encountered Flask and dismissed it, thinking, “Hmm, just Werkzeug and Jinja put together.” I’m not quite sure what prompted me to look further this past week. Maybe it was the recent comments by Armin and P.J. Eby’s responses introducing WSGI Lite.
The funny thing is I delved into Flask and liked what I saw. The URL routing decorator is quite attractive, and useful. I was largely convinced by the argument for having one template engine. The question then became: should I replace Mako by Jinja2? And, can Jinja2 do something similar to those Mako <%def%> tags I talked about earlier?
I was pleasantly surprised. In fact, Jinja’s equivalent for those tags are called macros and its documentation uses an HTML <input> for its example of a macro.
The bottom line is I very easily replaced Mako by Jinja2 (code in GitHub tagged as v0.2.3). I’m still exploring Flask and considering it as an alternative to CherryPy as the underlying framework.
Only for the sake of completeness, there is another promising lean WSGI web-framework called Bottle: http://bottlepy.org/
Indeed. I had seen Flask and Bottle referred in the same sentence. I wondered which one came first.
[Well, according to GitHub, Bottle's first commit was on 30 June 2009 subsequently tagged 0.4.10 implying an earlier history, and Flask's first commit was on 6 April 2010 to be tagged 0.1. So the Bottle came before the Flask.]
Your one template engine link gives a 404
Hi Regina,
As they say, “it works for me.” Maybe it was a temporary problem? The web page is at http://flask.pocoo.org/docs/design/ and you can use the TOC on the left side for “One Template Engine” or just scroll halfway down.
looks like the pocoo.org site is down.
Another nod to Flask–it runs surprisingly well on Google App Engine.
See https://github.com/kamalgill/flask-appengine-template for a boilerplate starter template for running Flask on App Engine.
Pingback: Joe Abbate: A Funny Thing Happened on the Way... | Python and PostgreSQL | Syngu
Pingback: Dueling Frameworks | Taming Serpents and Pachyderms
Pingback: Database User Interfaces – Pagination | Taming Serpents and Pachyderms
I am invested in CherryPy and Mako the only thing that has me searching for alternatives is lack of support for xhr2 file uploads. I would switch to flask but I don’t see it documented anywhere that it supports xhr2 either.
I wasn’t able to determine if Flask-Uploads (an approved extension) supports what you want, but it may be worth your time to check it.