The Fluther Blog

Back to Fluther

What is Fluther?

Fluther is a free Q&A collective that specializes in getting
fast answers from the right people. Check it out!

Going for a trot on the Django pony

11:11 am

I first knew I wanted to learn Django when I saw the DjangoCon 2008 keynote talk by Cal Henderson, subtly titled “Why I hate Django”. I highly recommend watching at least part of the talk.

I’ve been hacking on Python for a while now but until I joined Fluther back in September I had never done Python at work. My previous job at Yahoo! had me building front-to-back Java applications (which isn’t the standard there in case there’s some confusion). I used to have to go through 60 second builds just to test even a minor Java code change (CSS and JS reloaded when they were changed). With Django, that’s no longer the case.

The shell and the admin interface

Probably my favorite thing about Django is the shell and the admin interface. The shell is an environment that allows for testing, debugging and fixing things that would have been nearly impossible to do in my previous environment. Instead of writing code and compiling and hoping it works, realizing it didn’t and then hoping to catch a breakpoint and step through things looking at deeply nested variables, I can just pop into the shell, grab an object and manipulate it using auto-completing methods and properties until I can accomplish what I set out to do.

The admin interface—because it understands your models—lets you do all the basic CRUD operations on your data. With a tiny amount of work you can easily add search fields and filtering options. Sorting is already built-in.

What’s great about the shell and the admin is you get so much for free.

Templates

I found Django’s template syntax particularly frustrating at first. JSP is a relatively powerful language and you can easily end up putting a lot of logic that should be in a controller or model into the view. Django forces you to put it in the right place by not allowing nearly anything in the templates so that they remain just templates. It’s a frustrating but smart move that’s really helped me in the long run.

Models and migrations

Models and migrations are way better than what we were doing in Spring which was entirely custom SQL scripts with no backwards migration capability (unless we manually wrote it). With South, migrating forwards and backwards is pretty effortless. Unfortunately, the learning curve is not insignificant. It’s definitely worth the effort to get to know because in the long run it saves a lot of time (and pain).

Pros

  • Django documentation is pretty decent but I still wish people would just copy the PHP-style user comments. (PHP documentation > Django/Python documentation > Java documentation)
  • Template language forces you to keep your logic in Python
  • Django uses Python for settings and configuration, not XML files (Spring, I’m looking at you)
  • Shell lets you quickly test and develop things
  • Admin interface gives you so much for free
  • And let’s not forget, it’s Python

Cons

  • Relatively slow language
  • No split database support (then again we don’t need it…yet)
  • Documentation could rise to PHP levels of awesome
  • Setting up a new Django projects can be a bit of work
  • The learning curve of South is steep
  • Why isn’t South (or something else) part of Django?

Conclusion

So far I’d describe my experience as nothing short of magic (that can’t be removed).