The arrow of time

Ivan Voras' blog

Good first impressions on Werkzeug

I haven't changed my opinion on Python's performance but it still is a great platform for doing small projects quickly. I've chosen Werkzeug for my project and so far I like it. It has just the right mix of low-level and high-level funcionalities for what I'm doing. Here are a few notes about it:

Luckily, Werkzeug concentrates on one thing only and doesn't try to be everything for everyone - and what it does is a framework for web applications. Everything else - like templating, database access, etc - are left to outside tools, which is as it should be. In this particular case, I'm going with Mako templates but I'm doing my own database access. It is a "pure" application framework and not a low-level page processor like PHP is.

One thing I found out later but immediately liked about Werkzeug is its concept of "routing". For example, look at this:

Rule('/all/', defaults={'page': 1}, endpoint='all_entries'),
Rule('/all/page/<int:page>', endpoint='all_entries')

The "Rules" are W's model of mapping URLs to code. So for example the first line says there will be a "/all/" URL which maps to "all_entries" endpoint (a function or whatever) and it will pass a default data dictionary ('page': 1) to this code. This is all farily standard - what I'm aming at is the second line: it basically says that there's a special part of the URLs (think something like regex matching), the "<int:page>" part, which will match the integer from the URLs to the "page" item in the data dictionary passed to the specified endpoint.

This is an excellent way of thinking about the whole thing, if only because it produces very nice looking URLs (no cryptic query strings!).

HTTP response codes are basically exceptions in W. Redirecting the user to another URL is basically a line of:

raise RequestRedirect('/somewhere/else')

It promises to be a very interesting framework to work with.

#1 Re: Good first impressions on Werkzeug

Added on 2010-07-25T23:42 by dzen

url routing is not only implemented in werkzeug but also on django, and on google appengine.


Post your comment here!

Your name:
Comment title:
Text:
Type "xxx" here:

Comments are subject to moderation and will be deleted if deemed inappropriate. All content is © Ivan Voras. Comments are owned by their authors... who agree to basically surrender all rights by publishing them here :)