The Onion Uses Django, And Why It Matters To Us

We wanted to post earlier why we like/use Django, but, we get pretty busy around here, so a bit late. Sorry if this is duping any existing threads.


This is not a Drupal vs Django fight, we're not here to slag Drupal, Drupal has been important to The Onion, but The Onion decided to stop using Drupal a long time ago. The Onion deployed a Drupal site back in 2005, at the time it was the right decision given the resources, yet even then we were interested in using Python whenever possible. We feel it is a vastly better designed language than PHP and of course any framework you're using is only as good as the language. We started rolling out other projects, like The A.V. Club, in Django. Just this past weekend we switched over The Onion proper, and we're seeing immediate gains in speed, maintainability, and stability. As a team we have a pretty broad base of experience and I know we're all in agreement that what we've got now is better, enormously better. We're not just using Django, we have some other pieces that made our lives easier: git, PostgreSQL, VPS's. So this isn't just about The Onion using Django (and recommending it), but generally that you can make things better by investing time and energy into new technology.


It took us about 3 months to convert our old Onion site to Django while we also maintained and built on our other sites. We already had some components written for A.V. Club, including a strong article and image model, so we felt we could concentrate on coming up with good models that covered the necessary editorial cases. The hard part was more how to fit pieces of content from ten years ago consistently and cleanly than it was writing the code to make use of the final model. We broke out templates into nicely reusable components and made use of the Django template hierarchy. Multi-db made the conversion of data from a MySQL db to the PostgreSQL db fairly easy, so we could rerun importing old data into the new system and fix and tweak. There is an enormous advantage using Django, sorl and PIL for creating image crops based on templatetags which gives the editorial and design folk flexibility they need (no more css cropping odd-sized images into place). Again, lots of work went into actually cleaning a site that goes back to 1996, Django allowing for a relatively minimal amount of coding -- particularly when it comes to the admin side for content entry, Django trunk we found almost ready to go as-is (something we did not find with previous Django). That we could use the Django admin rather than create custom entry forms I think saved us 2 months work.


Cleaner. Much cleaner. Proper unit testing. Real reusable components across applications. An ORM rather than a just a series of functional query helpers. Tighter conventions (q: how often do people using Python argue about bracing styles? a: they don't). We can update then test a Django core change without worrying about having to take apart our applications, and if we do need to make a change, it's easy to do because there's less, much more readable code. Every member of the tech team can meaningfully contribute because there are fewer specialized or hacked together pieces. We can move more quickly on large changes because of all these reasons. And we're more stable because of all the previously expressed points.

-- The Onion Tech Team

25 thoughts on “The Onion Uses Django, And Why It Matters To Us”

  1. I’d be curious to find out if the workflow (or lack thereof) in the admin is something your editorial team is cool with and how, if at all you have modified this.

    Anyway, thanks so much for posting here.

  2. I’m here to slag Drupal. And Joomla!.

    And now back to your regularly scheduled non-just-for-fun-trolling comment thread.

  3. > q: how often do people using Python argue about bracing styles?

    a: they just grumble about lack of multiline lambda 🙂

  4. I’m curious if you use any django apps that didn’t come from the official django repository and weren’t developed by your team?

  5. Multi-db, so it’s sitting in production on the as yet unreleased 1.2 branch? Or trunk itself?

    If so, goes to show how relatively stable trunk is..

  6. > Tighter conventions (q: how often do people using Python argue about bracing styles? a: they don’t).

    If you think those arguments are bad then just wait until the spaces vs. tabs arguments begin.

  7. Why did you guys choose to hack Drupal so much rather than going the custom module route and keeping up with updates? I know it’s all water under the bridge, just wondering.

  8. This is a good piece, but it reads to me as “we moved from a product to custom code built on a framework”. Which is fine, if that’s what the business needed. Comparing an out-and-out framework with a product is apples and oranges territory though. I don’t see how a comparison is relevant.

  9. Darn. I was hoping this would provide a nice balanced, technical discussion of the relative merits between the two frameworks, with some actionable feedback for what Drupal could do to improve. But instead it sounds more like “We like Python better” and “We hacked a 5-year old Drupal install to bits and subsequently weren’t able to use better tools as they evolved.”

    Sounds like you’re happy with your new Django-based site though, and staying in the open source family, so kudos for that. 🙂

  10. I’m interested in how you sold this redevelopment process to your management; it’s common for a creaking old system which ‘does the job’ to be patched again and again until there is some kind of catastrophic failure, at which point a rewrite will be permitted.

    As far as I know, The Onion never had that kind of failure – do you have infrastructure-savvy management, or just a good developer advocate? Four developers working for three months on a project to rewrite is a considerable cost, and generally the people who sign the cheques don’t listen to arguments about maintainability or stability.

  11. * Did you guys follow any specific software development model that well suited the small team during these 3 months?
    * How does django as a platform handle (Number of concurrent requests/number of users per day a single web server can handle)? In other words, performance improvement over the previous platform?
    * Any “gotchas” you guys faced?
    * If django weren’t available, what’s your next choice for a python framework?
    * Given that most of the requests are probably for read only, what kind of caching mechanisms you guys prefer?
    * Any advise for others trying to build something of similar sorts?

    Thanks for sharing!

  12. A few other things I neglected to mention and weren’t mentioned anywhere else:

    * We’re using sphinx for full-text search. My integration of sphinx with the onion took me approximately 20 minutes (largely due to already having it running for avclub, but still highlights ease of code reuse without copy and paste)
    * nginx is our media server and reverse proxy
    * haproxy is amazing and saved me many headaches and turned the actual launch process of the site into (no hyperbole) a 5 second procedure.
    * mod_wsgi in apache is our current python deployment mechanism, though we’re looking at using uwsgi since it integrates well with nginx which is my favorite webserver at the moment.
    * simplejson is great when we can use json for integration, and is good when we can’t
    * we’re currently using capistrano (ruby) for deployment

  13. I’d like to know how much the out-of-the-box Admin site fits your use-case or if you had to create something more tailored to suit your purpose.

  14. thanks guys for sharing.. good stuff

    couple of scaling questions. What is the machine config and db(master-n*slave) config that you guys are using? Do you have any hick ups during the scale out?

  15. First, congratulations on the migration. Sounds like it was fun. Second, I work with PHP/Drupal. I haven’t hacked it as extensively as any of you guys have, but I’d say I know my way around it. Anyway, all I really do is PHP but I’ve been wanting to try Django/Python. How long do you think it would take someone who coming from Drupal and hasn’t worked with Python at all to create something nice with Django?

  16. “(q: how often do people using Python argue about bracing styles? a: they don’t)”

    Instead, they argue about tabs vs spaces… 😛


Leave a Comment