Mastering Django (part 1)

Motivation

I first attempted to learn how to use Django a little less than a year after it was first released, in the summer of 2006 when I was 19 years old. Young and still finding my footsteps with Python I, like many other Django users, grew tired of creating slightly different web application frameworks for each project (code reuse at that point hadn’t had its impact on me). Whenever I created a web application, I simultaneously ended up creating a dictionary-based (read: sprintf() like string substitution) templating system while the applications themselves were powered by mod_python. And then I heard about Django and gave it a shot. As a programming framework, I had to sacrifice API control and “buy in” to their system, but almost four years later, I’m glad I did!

Django’s motto is “the web framework for perfectionists with deadlines” and while I now believe this is a true reflection of its capabilities, at first I certainly didn’t. Like many now seasoned Django developers, I started learning with the tutorial on djangoprojects.com but I ended up quitting immediately. The context of the tutorial at that time didn’t make much sense to me especially as it showed off Django’s features on the command line and that seemed a far cry away from a website. A few months later however, I bit the bullet and gave it another shot and this time succeeded (and then the command line examples made sense). I used the improved documentation, learned where to ask for help, and read the source code to see how it all worked. Django has grown a lot since that time (it’s been amazing to see the growth). There are many entire books on the framework, scores of useful external websites, and countless applications available for you to take advantage of in your own project.

This article is intended to be a collection of resources for a Python programmer who wants to learn Django. You don’t need to be an expert, but I assume that you have read an introductory book on Python and know the basics. I hope this guide will prevent other programmers from giving up on Django like I first did and help them master the web application framework. After all, had I not taken a job where I needed to use Django, I probably would never be writing this. Now it is a pleasure to code Django applications and I wish to spread the joy to all who wish to use the world’s simplest web application framework.

I am dividing this article into three sections relating to the types of resources available to Django newcomers. The first is the print medium which is described here and is aimed for those who are beginners to Django development. I discuess a few of the books available and where to find them and then discuss my favorite one, Django 1.0 Web Site Development (read this first). The next installment will cover resources available on the official Django website (as well as official resources not on the site) and is intended for intermediate Django users (i.e. those have read a book on it and are familiar with the API). The third part will go over third party websites and other places on the web that contain valuable Django information and can be used by any Django developer. The last part will unveil resources to even the most experienced Django developers. I hope these articles will be useful to programmers with all levels of experience.

Django Books for the Beginner

Django started out as a proprietary framework and its founders were granted permission by their employers to release the code under an open source license (don’t we wish there were more of those types of bosses!). I doubt its founders would one day imagine the range of books printed on the web application framework but indeed the list is growing. When I first started coding using Django, there weren’t any books on it and I instead relied on shoddy documentation. If my knowledge of Django were suddenly erased however (but not my memory of trying to learn it), I would start out by reading a book.

The first major book on Django, The Definitive Guide to Django, now in its second edition, was written by Adrian Holovaty and Jacob Kaplan-Moss and is open source (i.e. it is freely available on the web but also published by Apress). While I haven’t looked at the second edition too much, the first edition was very much related to the documentation (no surprise there since its authors are also the founders of Django). I definitely recommend checking that site out as a more in depth, example driven accompaniment to the official documentation.

The book that I recommend to beginners however is called Django 1.0 Web Site Devlopment by Ayman Hourieh. Published by U.K. based Packt Publishing, I would recommend any book published by them as they are always about cutting edge technologies. This is of course a huge risk because the book might be quickly outdated as the API or paradigm of the project changes. Cleverly though, they seem to recognize that most projects strive for backwards compatibility and their bets seem to be paying off. In addition, while all of Packt’s books are available in print form, they also distribute eco-friendly e-books. The books are DRM free and are delivered in seconds via Adobe Acrobat which means you can copy and paste code samples from your favorite PDF viewer. While I’m a sucker for print books, Packt has an especially cool deal where for a little more money you can download the e-book version while the book is being shipped to you! Overall the company has a penchant for publishing books on open source topics and delivering the books in the most flexible manner possible (free shipping anyone?) and I like that.

Django 1.0 Website Development

Django 1.0 Website Development

NOTE: I want to first be up front about my Django book selection and say that I received this book for free in return for a review of it on my blog. However, there wasn’t anymore to it then that and I could have written a separate post about it and not have recommended it in this Mastering Django series of articles. In other words, after reading it, I really do think this is the best Django book available for beginners which is why I am highlighting it in this set of articles. While I haven’t read every Django book, I have those published by Apress and Packt (i.e. the best ones in my opinion) and I think I justify my selection just fine. Now that that is out of the way… let’s get back to the show.

About Django 1.0 Website Development

My favorite aspect of the book is its format. Most of the other Django books I’ve read or glanced over cover each topic in a disparate fashion using petty examples here and there. Mr. Hourieh makes it clear that all Django topics will be covered in terms of how they relate to the development of a social bookmarking project. This is my favorite format for introductory programming books as they best model real world development. The only trivial downside is that you probably couldn’t easily just open up to a chapter and begin coding along with the book. This is perfectly fine for the beginner because you should read the whole book anyway so you have maximum exposure to the Django API and learn how easy it is to extend your project with existing code. In addition, the author steers clear of discussing, for example, different arguments you can supply to different functions and focuses on feature based development, introducing new concepts as opposed to alternative or slightly different ways of doing the same or a similar task.

Social bookmarking is good topic for introducing Django because its core is very simple and that is where you start. Of course such a project can easily add m0re features and this is the approach Mr. Hourieh takes. Obligatory introductory material is of course present as is installation help in the second chapter. Chapter three goes over Django’s MVC paradigm all in one swoop whereas other books tend to take too much time on discussing this and its differences between MVC, etc. Immediately after, readers jump right into the most popular part of django.contrib (Django’s contributed applications — in the spirit of Python’s all batteries included model) and the author discusses how to use the django.contrib.auth application (the user management module) in chapter four. Template tags are covered in chapter five and Django and Ajax is then covered in chapter six. This chapter is especially refreshing. Using the popular jQuery framework which is briefly described, topics like in-line editing, “live” searching (i.e. dynamically loading results), and finally Ajax powered search auto-completion now common on many websites like Google and Bing (I’ve tried several Ajax toolkits and jQuery is the best and most users seem to agree. In the spirit of publishing books that are on hot topics, check out Packt’s Learning jQuery 1.3 for a great introduction). Chapter seven continues to add to the application by implementing bookmark sharing between users as well as introducing django.contrib.comments (Django’s comments application). Chapter eight presents the Django administration interface, user and group permissions, and also discusses how to customize the admin. The remaining chapters cover the rest of the API such as RSS feeds, advanced database querying, internationalization, caching, deployment, and much more. Chapter twelve goes over other parts of django.contrib that are available to the user but no examples are given which is fine considering the depth the other topics receive.

So there is an overview of the book’s organization. I hope it is clear that the book is project oriented which in my opinion makes it all the more practical to a beginner who perhaps isn’t yet sold on Django’s API. You start out with the basics and then immediately jump into Django’s contrib applications. This approach differs from The Definite Guide to Django in that API nuances aren’t discussed as much. You spend your time creating a website as opposed to playing with objects in the terminal which is only really useful if you have prior experience with Django (this might seem like an overstatement but I really think that playing with objects in the terminal is confusing to budding web developers). While Adrian and Jacob’s book is certainly interesting and well written, again, it is very documentation-like, and Mr. Hourieh does a great job at engaging the reader by including material on how to accomplish some of the more popular features found on the web today like tag clouds and object sharing between users. In short, the structure of Houieh’s book is better than The Definitive Guide to Django’s in that is “newbie” friendly.

Another great idea of the author was to keep HTML and CSS coding to a minimum (except where required by Ajax). This keeps the book focused on Django and again reflects real world applicability as the people coding Django applications are usually not those writing the CSS to the XHTML template design.

Final Thoughts

I hope that if you are new to Django, you know what books are available to you and why I chose Django 1.0 Web Site Development as the best for beginners. Don’t be put off by the fact that Django’s current stable release is 1.1.1 — all the examples will work just fine as Django strives hard to maintain backward compatibility in the development process. Despite being given this book for free by the publisher, I am happy to receive it because it is the best in that focuses on how to make a cool “Web 2.0″ website using what modules Django has to offer. Once you have read this book, you are ready to explore in depth Django’s website (including its trac site at code.djangoproject.com). Part II of mastering Django will explore the project’s homepage in detail (as well as Django’s presence on Google Groups and its IRC channel). For those who have read Django 1.0 Web Site Development, the next part will help you fill in the cracks and aforementioned API details deliberately left out to keep you focused on rapid development. I think this book is completely in tune with Django’s slogan as it guides you on how to create a feature filled website quickly.

Now that Django has books published on it, beginners or casual coders can read them as a first step into becomming Django masters. I welcome any and all comments and am especially curious on what users thought of some of the other Django books out there and how they related the Django newcomer. Stay tuned for part 2!

  • Share/Bookmark

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.

Comments

Thanks so much, looking forward to the series. I really want to get into Django and this is going to help a LOT!

Schalk Neethling
The OpenSource Hub

Nice article, though i’m a front-end developer and really can’t find my way in the mess of things… don’t have a clue how this django could assist me..

[...] Mastering Django (part 1) Django Tutorial [...]

Great article! Is part 2 coming soon?

Yes article two is coming soon! I’m finishing up college now so I’m really busy writing papers but I definitely am going to write the second article this weekend and it will be the best of this series so stay tuned and thanks for reading! Cheers!

Leave a comment

(required)

(required)