Tuesday, June 16, 2009

Book Review: Python Web Development with Django

Disclaimer: I received a review copy of this book through the PyATL Book Club.

The stated goal of the book is "to help you get things done" (using Django for web development). As a relative beginner with 3 years of Python and coming on 1 year of using Django for web development, I figured that I would either be the perfect audience for the book or already too advanced to get much out of it (it's been a pretty obsessive year).

The book starts out with a nice introduction to Python. I thought that this was a great place to start because the Django documentation intentionally assumes knowledge of Python and the free online django book dives straight into the merits of web frameworks and the history of Django. So, already the book is setting itself apart a bit from the free online resources.

I remember feeling a sense of clarity while reading the introduction, a good compromise between trying to be comprehensive and terse at the same time. The intro does a good job of presenting what you really do need to know about Python and some common pitfalls. Interesting that nothing is said of the string.format() method which is somewhat unfortunate as the official python docs say:

This method of string formatting is the new standard in Python 3.0, and should be preferred to the % formatting described in String Formatting Operations in new code.

But, alas, I (not to mention the official Django docs and probably 99% of Django devels) have always used % formatting and will probably continue to do so for the near future. I will be interested to see how Django and Python move forward. Actually, checkout the Django source itself:

skylar@ABC255:~/svn/django-trunk$ grep -r % * |grep \' |grep -v svn|grep -cv dateformat
skylar@ABC255:~/svn/django-trunk$ grep -r % * |grep \" |grep -v svn|grep -cv dateformat
skylar@ABC255:~/svn/django-trunk$ grep -r '\.format(' * |grep \' |grep -v svn|grep -cv dateformat
skylar@ABC255:~/svn/django-trunk$ grep -r '\.format(' * |grep \" |grep -v svn|grep -cv dateformat

Well, perhaps the authors are right in not mentioning the string.format method after all.

A small correction that I can't pass on mentioning here (being a math nerd): the book states that list.sort() sorts numeric values from smallest to largest. If I may present a list that I believe is ordered from smallest to largest: [1,2,3, -100000, -9999999999]. I spoke to Wesley Chun and he said that he would probably change to "the most-left on the number line to the most-right on the number line." I think that is about as good as it can be phrased without opening an analytical can of worms that could erupt and engulf us all! Coming back to earth after my self-satisfied, math-degree-induced intoxication, I learned a little about generators, the finally clause, raise and other aspects of the Python language that I have mostly danced around. Almost everything presented in the chapter I already knew; but, perhaps rather than struggling for years to understand these concepts I could have just read these ~50 pages? I did get a nice sense of clarity and a feeling that I was consolidating what I already knew into a more cohesive force.

Chapters 2 and 3 are fair enough, "Django for the Impatient: Building a Blog" and "Starting Out". Nothing really stood out as exceptional. I could imagine that I have just worked my way through the documentation's tutorial and these two sections really helping to expand my horizons and to clarify a few things.

The next section "Django in Depth" gives an enjoyable read of the M, the V, and the T in Django (change the letters if you feel the need). At only ~60 pages I don't know if the authors were intending this to be Django's K&R . But, it seemed to be just about right for my particular skill level. I definitely came in with a lot of the information presented; a few of the sections definitely pushed into areas I hadn't bothered considering too deeply like abstract base classes, multi-table inheritance, extra() and fixtures (in the Models section). I enjoyed the authors' treatment of the request and response objects in Django and felt my understanding enhanced. I have been making things work but not necessarily seeing the forest for the trees. I'm not sure how the sections on forms and templates differ from the official documentation; although, it is nice to have a document that is intentionally ordered and requires no electricity.

"Django Applications by Example" had some fun examples with some real-feeling problems to overcome. We get a custom field, use the flatpages app, use generic views and custom views judiciously, implement a search request-handler, deal with users and the admin app's current insistence on mutual trust where users have the same permissions.

I like that the authors went ahead and made use of "AJAX" with jquery in their liveblog example app. I'm biased because I use jquery. But, this is something that you will never see in the official docs or djangobook: A JAVASCRIPT SNIPPET! It definitely got my juices flowing about how I can make my own JSON API views. Usually I have just rendered an HTML snippet with my view and the asynchronously inserted it into the DOM (actually preferable in a lot of situations) but it's nice to see how a JSON api would work. The pastebin example also had syntax highlighting with javascript which was nice. I even learned about the "pre" tag. And there is a little introduction to cron with the Django ORM.

The "Advanced Django Programming" chapter is kind of a hodge-podge of things that will probably be encountered eventually if you work with Django enough. Django's power by virtue of Python's power is shown with examples using the csv and pycha modules. External python modules might have been it's own chapter but these topics are presented alongside customizing the admin, custom managers for your models and extending/replacing the templating system. Then, in "Advanced Django Deployment" we talk about cron, caching, testing and other miscellany. These ~50 pages seem a bit like the authors were getting tired and so rather than properly organizing they kind of just tacked on some extra things that they felt were neglected or not properly treated in other chapters (reminescent of tacking on some css rules at the end to get your website out the door when you know it would be more proper to factor it in to various external files). Here I can cut them a break because I am feeling like cutting this review short and it is barely a page ;)

Overall, I don't know if this book will "help me get things done". Actually, I rather think that the online book and the django documentation are first choices in a pinch and trying to really "get things done". However, the book gave me prospective on quite a few things that are either lacking from the documentation or are just presented in a different order. I like the way that this book is logically ordered.

Most importantly the book allowed me to get out in nature and hang out with my girlfriend (sans computer) while still sharpening my Python/Django tools. Plus, your mind can get a little scrambled with 10 tabs of documentation up in your browser alongside 5 blog postings that you are reading simultaneously. Sometimes it's definitely nice to have a single source with a linear organization.


inetsolution said...

Its highly informative. I would be visiting your blog hereafter regularly to gather valuable information.


Anonymous said...

Because the website will be your company's main representation online, you have to choose the best Boulder flash web design to done this job for you. I got a good site to solve all your problems my personal experience with them is great.

kristinawils said...

Great post and very well written, that will really help you to learn Web Design, web development and SEO Strategies to help businesses web design company . You can find out many useful information about web design, seo and his work by visiting his blog and I Just wanna say thanks you for the information you have shared. Web Design Company India