Constant Contact Labs Developer Blog

  • Rails vs Django: A Developer’s Comparison Posted Friday, February 12, 2010 Huan Lai 38 Comments

    Rails vs Django

    As you might know from reading some of my previous blog posts, I’ve been working with Python and Django pretty extensively over the last year, mainly for rapid prototyping and developing relatively simple web applications (including a Facebook App). During Cool Stuff Week I decided to try using Ruby on Rails (RoR) as the base framework, as a learning experience more than for any other reason. So what’s the difference between these two popular dynamically typed frameworks?

    Note: I am first and foremost a backend developer and have bias as such.

    Both Rails and Django are both open source web application frameworks intended for rapid development that follow some form of the model-view-controller architectural pattern. RoR, developed by David Heinermeier Hansson from his work on Basecamp, a project management tool by 37signals, is the defacto standard web programming framework for Ruby. Django, developed by The World Company to manage several news-oriented sites, is one of the most popular web programming frameworks for Python.

    Both Rails and Django use HTML templates extensively. The key difference lies in the fact that Rails templates use inline Ruby code fragments whereas Django uses a specific templating tag language. Rails allows for more complex functionality if need be, but Django is simple enough that web designers with minimal programming knowledge can build templates. Although Django makes it easy to develop custom tags that can be used in the same way as native tags. I’ll have to pick Django on this front.

    Along the same theme of presentation layer, Rails and Django are very different in their views towards JavaScript and AJAX. Rails comes shipped with the Prototype JavaScript framework and the Scriptaculous JavaScript controls and visual effects library. Because of this standardization, Rails also ships with a number of ways to take care of the dirty work when it comes to sending and responding to AJAX requests. Django on the other hand comes only with a JSON module, leaving any and all JavaScript decisions and development to the developer. While I have not yet had to write any applications that utilizes AJAX, I can definitely see why the built in support for it by Rails can be very useful. At the same time, there is also an advantage of not having any sort of JavaScript decisions made for you in Django. For the Facebook Join My Mailing List project, I noticed some oddities with Facebook’s FBJS. I can only imagine how Rails’ JavaScript integration behaves in such an environment. As I haven’t had enough time playing with Rails, I can’t really judge the pros and cons and will leave this a tie.

    Both Rails and Django use object relational mapping to link the application to the underlying database, but Rails and Django have very different ways in which model objects are defined. In Rails, model attributes are not declared in the class definition. Instead, Rails can retrieve all of this information from the database based on the class name (by convention, database tables corresponding to model classes have the same name, but there is a way for the developer to write extra code to deviate from this convention). In Django, the developer is required to explicitly specify each attribute of every class. From there, there are standard tools for creating a database schema from the model definitions. I haven’t tried to change the database schema for my Rails project, but I’ve read that it has a migrations mechanism for easily doing changing the database schema while preserving and appropriately modifying the existing data. I did have to do this in the past for Django projects and it is rather painful. I’ll have to pick Rails on this front.

    Along the same theme of managing the underlying database, Rails and Django have different ideologies for admin pages. Django has a built in system for automatically generating admin pages for model objects with ways to customize the presentation. Rails does not come shipped with an automated way to generate admin pages, but there are plenty of 3rd party plug-ins out there to do the same thing. As I haven’t actually tried out any of the plug-ins for Rails, I can’t really judge how well they work, but the convenience of having a built in system that works quite well makes me choose Django as the winner on this front.

    Both Rails and Django allow for the use of regular expressions to customize the mapping of URLs to controller actions. Both are flexible enough to allow you to create pretty much any mapping scheme you wish. By default, Rails also does automatic URL mapping based on the class and function names within controllers. This is further evidence of their Convention over Customization philosophy. I’ll have to pick Rails on this front.

    From reading up on both frameworks, there is a subtle, but noticeable, difference between their philosophies. Rails focuses on having the framework do stuff in the background for the developer, making it all seem simple and easy. The Django framework does just as much heavy lifting for you, but emphasizes on the fact that it is saving you from having to do these things yourself. These two ideas seem to be the same, but the Rails point of view has more of a “magic” visage whereas Django has more of a convenience one. I personally prefer Django’s approach to this, but I’m sure there are plenty of people out there who would disagree.

    At the end of the day, both frameworks are great. There really isn’t a clear winner and there really isn’t much incentive to migrate in either direction if you’ve already gotten entrenched with either camp. But if you’re currently out shopping for a framework to use for a new project, the biggest factor in determining which to use is your preference of Python vs Ruby. I’m already in the Django camp and don’t see any reason to switch over, but you can’t really make a bad decision with either of these frameworks. I’m sure there are plenty of people out there with strong views in either direction, tell me how you feel about these two. I’m going to try to spend a little more time with Rails to give it a better analysis; anyone with more experience with Rails than me (not really all that hard) want to comment?

    The opinions expressed here represent those of the author and not those of Constant Contact, Inc. Read Blog Terms
    Next Post Previous Post

Comments (38) +comment on this post

  • Sumit Chachra | 8:18 PM March 3, 2010

    If you’re a newbie developer then Rails wins ... anything more complex or if you like having more control or if you like having your app not randomly fail on you then go with Django!

    Nice real-world comparison!

  • iJames | 5:11 PM March 18, 2010

    I’ve been beating my head against one of your ties.  AJAX and Javascript.  I played with ROR first, and really liked how easy it was to swap out full screen refresh with a partial refresh using Rails partials.  Also I’m not sure how easy it is to determine PUT, GET, POST, UPDATE http requests on Django whereas on Rails it seems inherent.  I’m doing a Django project now and have learned about “inclusion tags” which might work for Ajax similarly.  I’m really hoping to have a nice framework for talking back and forth with the server and refreshing what needs to be refreshed easily.  I’ve been using tacnite for trying that out.  It’s a cool way of using a standard system for modifying parts of a DOM in a standardized way from the server.

    Thanks again!

  • Frank | 2:00 PM April 28, 2010

    Very enlightening article. Since I started working on a project in Django, I’ve been considering RoR but knew (and like) python… At the time this pushed me to “just start” with Django. All in all, it appears to not matter. Your article has been the most enlightening between the two frameworks thus far. Thank you.

  • Jens Backman | 4:47 AM May 9, 2010

    For Django database migrations, check out South.

    I’m not sure about the PUT/GET/POST/DELETE detection, but I guess you could do something like this:

    if request.method == ‘GET’:
    elif request.method == ‘POST’:

  • GEoff | 1:54 AM June 7, 2010

    I feel that this article as well as the comments, fail to address one small facet of this discussion. Language choice. I personally prefer pythons syntax and simple power over Ruby. Ruby in my opinion is the lesser used language at the moment and I think this is for good reason. Python really is a very enjoyable language to work with. Im saying this having had very little experience with Ruby, but from the experience I have choice is python / django over ruby / rails.

  • Huan Lai | 9:25 AM June 7, 2010

    Thanks for the feedback, everyone.

    @Jens, I’ll look into South the next time I need to do some sort of migration. I read up on it a little bit based on your recommendation, and it seems to be pretty well supported.

    @GEoff That is actually the reason why I choose to work with python/django as well, language preference. That is pretty much the conclusion I made in my comparison as well - that both had their pros and cons, but both are very solid frameworks, and the final decision should be in language preference.

  • SeanG | 2:31 PM August 5, 2010

    Thanks for the great real-life comparison. I’m kind of the opposite of you. I have experience with RoR and am trying out Django for the learning experience. I was curious if you could elaborate on (perhaps with an example) your comparison of Rails “magic” vs Django’s “convenience”... that distinction eludes me.

    From my Rails experience… here are my gripes about the RoR platform:

    - The Rails core development team makes no apologies when it comes to upgrades and releases. New rails versions almost invariably deprecate/break existing rails applications. If you don’t stay current with the latest release (taking every intermediate release as it’s available) then your application will rot away.

    - The Rails feature set and convention is driving madly to a RESTful framework. I’ve found the more they drive towards this, the more difficult it becomes to write “real world” applications. Simple tutorial applications that are just a catalog of database objects work wonderfully well in this framework but real world applications (in my experience) spend most of their time ignoring it.

    - While it adheres quite well to the ‘DRY’ principle, I wish it would consolidate the information more. In particular the Database ‘Model’ objects are spread quite thin. If I want to know what methods are available on a particular Model, I have to search through the Model (which has the custom methods) and the migrations (which have the object properties) to figure out what method I should be calling (or the physical DB schema when the migrations are too complicated).

  • ravi kumar | 7:15 AM December 15, 2010

    python has elegant syntax
    can create easy debuggable code
    both simple and powerful

    python has a strong support from google

    python is extensively used in other fields like scientific etc so as a django developer one need not stick to web development only

    i dont know how extensively ruby is used in other fields other than web development

  • MidGe | 7:00 AM January 2, 2011

    I have had the pleasure and the experience of frustration learning both DJango/Python and Rails/Ruby for about three weeks each.

    I agree with the author’s point, but I would like to add:

    Firstly, that Rails/Ruby felt heaps flakier than Django/Python.

    Secondly, the setting up of development environment and deployments, with the available and “needed” extra tools, if you want to repeat the experience, is again very much harder and flakier in Ruby/Rails than in Python/Django.
    By choice I would go Django,but because there is an opportunity for some work, I will go the RoR way :(

  • bs | 12:24 PM January 3, 2011

    This has been very informative.  I’ve been rooting around trying to find an answer to which is better.

    In choosing between RoR and Django, does it matter what the web app’s function is?

    I’m creating a paid subscription concept where my website users create their own profiles, and then can search and browse for profile views of others, with some limited connectivity (bookmark and ‘like’). They can also create managed lists of users they’ve found, and do a little private mailing.  I have clear wireframes and I do want it just so, and not be limited by any “that’s not possible” talk.  Finally, I like the idea of engine-yard like hosting support. 

    And of course, I want all of this on a low budget.  LOL!

    Does python or RoR offer me a better solution?

  • Huan Lai | 1:45 PM January 3, 2011

    Well, from the sound of your requirements, I’m pretty sure either platform would be able to handle your use case pretty well. As for engine-yard like hosting support, for python/django, you could try out Google App Engine, which supports django pretty well. Fair warning though, Google App Engine’s database layer follows a NoSQL format and won’t be able to handle a lot of the basic functions that you’re used to with standard relational databases, so you need to design your project accordingly. Besides that, I’m not very familiar of hosting supports. In terms of 3rd party hosting, I’ve tried using Amazon EC2, but its a bit on the costly side.

  • bs | 6:32 PM January 3, 2011

    thanks Huan!

  • op | 2:47 PM February 6, 2011

    I enjoyed reading your impressions of django and rails. I’d also be interested in learning about hosting availability, affordability, etc. Sometimes this helps make a decision between similar development environments/frameworks.

  • yuping | 2:03 AM February 10, 2011

    Style and style is amid the finest objects individuals spend concern to these days. everyone has obtained to arranged on clothes, but there a & fare all those individuals who hold acquiring dressed inside the morning to some abercrombie complete new level. They don’t get dressed getting dressed,
    abercrombie and fitchthey get dressed to create a statement.

  • Javier Isassi | 7:02 AM February 20, 2011

    I just started using Python a year ago. My background is c++ with 2 years using Ruby and Perl. I find Python to be “Perlish” in the way their expressions tend to resemble simple function calls. Where Ruby changes a char to an int using a an object oriented model: myVar.to_i , Python uses (python dev’s favorite pejorative “magic”) to the same job: int(myVar) ..where that int() function comes from? Are we going back to ANSI C? Personally, I like my egg broken at the larger end wink.

  • Karim Naufal | 11:08 AM February 24, 2011

    Thanks a million for sharing, finally a decent comparison.. smile Searched for it for a long time!

  • Huan Lai | 1:53 PM February 25, 2011

    @bs, Karim: You’re very welcome. I’m glad you found my article informative.

    @op: In terms of hosting availability, neither of them are as universally accepted by all hosting providers like PHP is, but they’re both catching on, though perhaps not with the super-budget providers. I think python might be more common than RoR, but that might just be as CGI. Since RoR is the pretty much the defacto standard for ruby web applications, whereas django has fiercer competition (pylons for example), the availability should be about the same. You shouldn’t have too much problems looking for a fairly priced host that supports either platform.

    @Javier: I agree that Python is a lot more “perlish” whereas ruby is a lot more OO (perhaps more OO than most other languages out there), but in terms of “magic”, I find that Rails is the definition of all that is magical with frameworks. Rails does a lot of things automagically for you, so long as you follow their conventions, even more so than python+django.

  • ErikH | 11:52 PM March 9, 2011

    Top notch assessment, Huan. Thanks for putting it all in one place! I’m not a strong coder myself but I do server administration and killer CSS—because I use Python for scripting I really wanted to dive into a solid framework and build on what I already know. I was conflicted though b/c all of the devs I know are in love with RoR.

  • Olleicua | 9:08 AM March 12, 2011

    I just did project for a course on internet technologies comparing the two and I had a similar feeling of “magic” from Rails.  I think this is a result of the convention over configuration approach.  I liked Django better because I felt like if I wanted to tweak the way something worked, I could find it easily in a configuration file.  In ruby I felt like the way things worked was just kind of handed to me by a tutorial and if I want to tweak something I’d have to dive into the back end.

  • Tony | 10:33 AM April 14, 2011

    In reading through these comments, I noticed a similar theme expressed from python developers: that python gives you more control.  This is really just a case of programmer ego, and can get you into great trouble.

    However, if you do want power and control, why not use C++?  C++ is a very modern language with features like templates, pattern matching, functions as objects, closures, generic containers, polymorphism.  It’s also blazingly fast and “properly” standardized.  Surely, if your aim is for control over the details, C++ reigns supreme.

    When all is said and done, we don’t use C++ in web development that often; for good reasons too…

    Fore the record python is a good language - I’m not hating.

  • Manga Reader | 12:34 AM April 16, 2011

    real-life comparison! I’m on the way to choose frameworks for my future projects and found here and very informatics comparison. I only have experienced ASP.NET and PHP and I’m wondering if I can learn RoR to speed up my social web project and is that app easily to deploying maintaining. What kind of hosting and components need for RoR ?

  • JimR | 2:17 PM May 16, 2011

    Thanks for the useful article and comments. I’ve done a couple of small personal projects in Django, and I’m in the process of doing the same with RoR. My first impressions:

    - I prefer the “explicitness” of Python over things done “automagically” (as Huan said). I think it makes for more readable and easily-maintainable code.
    - Rails seems to have good migration built-in; I can’t say how Django’s South compares.
    - I personally don’t mind that Django’s template language is less powerful.
    - I get the impression that there are more employment possibilities for RoR than Django.
    - RoR definitely pushes RESTful. I don’t know if this is good or bad.

  • Ken | 8:36 AM May 21, 2011

    I want to point out that while Rails comes shipped these libraries, you can easily swap in jquery or just delete them - they are not enforced you on at all.

    In fact, I would not use Rails’ special AJAX support honestly, because it will eventually get in the way the more complex your ajax app gets.

    When it comes to ajax and more logic needs to be put to the browser, the less the framework matters as far as ajax is concerned. I will admit that having REST baked into RAILS just makes this easier though. I’m not sure if Django does REST as easily, but this is actually pretty important.

  • Trevor | 8:23 PM June 28, 2011

    Nice comparison. You are missing a few things I tend to look for, maybe others do as well. Debugging! I guess this is language specific but I think it’s important to note the difference between the 2. I have a strong Python background and do enjoy dabbling with Rails from to time but I find pdb is just amazing, equivalent for ruby/rails?

    Another thing I am very very surprised to not see in this article is Django forms and how the modelforms and formsets work in comparison to what rails uses. I am not sure what rails does for forms but I am pretty sure you still need to build them out with regular erb.

    Other things to consider is middleware, decorators, and context processors in Django really help in the MVC life cycle. Now sure how rails compares on this front.

    Write up a part 2 for the more the advanced smile


  • Andolasoft | 4:58 AM July 28, 2011

    I really enjoyed your blog post. I bookmarked your page so I that can keep track of your future post.

  • Likit | 5:51 PM August 13, 2011

    @Javier int is a constructor of type int which is an buitin object. It just returns an int object when it is invoked. It’s not a method of a string object as it is in Ruby.

  • Niall O'Connor | 8:28 AM September 9, 2011

    Rails tends to break and destroy apache more.  You can port a rails project onto Google App Engine.  Its seems the lords at Google favor Java, Python and Go.  I prefer python as a language. I prefer django to rails but prefer web2py to django.  I would recommend django because once you are used to python there are a larger number of great frameworks available.

    I started out on ruby but switched to python. I would group rails with HD-DVD, and BetaMax.

  • Andy | 7:27 AM November 19, 2011

    Not to break everyone’s concentration on their tunnel vision programming nightmares or anything, but just FYI ... another useful programming language that just came a few decades ago is called java. I realize most languages were created for a reason and have their purpose (I use many of them everyday including Python). One exception is PHP (it’s only purpose is to destroy human minds).

  • Conan | 1:51 PM December 8, 2011

    Nice comparison!  I’ve been doing Django development for many years, and while I love Django, my primary reason for sticking with it is the ability to use Python.  I’ve tried Ruby several times and just can’t find the love.

    One place I would disagree with you is on the template language.  Django’s weak sauce template language is incredibly limiting.  Why would I want to learn *yet another language* to make things work?  I like Python, and my project is simpler with less languages.  I can still choose to keep my embedded Python simple on my own.  Fortunately, it’s really easy to combine Mako with Django to accomplish what I want.  All the power of Django’s back end with a nice Python-based template system on the front end.

  • Bill | 2:33 PM December 8, 2011

    Good comparison on Rails vs Django.  I agree with your assessment of it being a language and environment preference.  I’ve been using Rails for the past few years and like it.  There are times when figuring out what is going on behind the scenes gets tricky but not impossible to figure out.  I’m a long time Java developer and C/C++ long before that.  Never considered scripting languages worthy of full blown applications till I found Python and Ruby.  I chose Ruby a few years ago when I was working on a project with someone that wanted Rails.  I did an evaluation on it and was impressed.  It’s grown and evolved considerable since..  I use AJAX quite a bit but roll my own in using jQuery in templates as opposed to the built-in Rails helpers for that. Rails migrations are great and work well as long as you know what you’re doing with them.  There’s something to be said for convention imposed in Rails as it makes navigating other code a bit more intuitive.  I still do Java commercially and it works well.  However, these days for building web applications I prefer Rails as I find I’m more productive with it (never thought I’d say that).

    I’ve done a bunch of PHP and it works and there’s a boatload of resources for it which is about all I’ll say about that.

  • Vin | 8:33 AM January 8, 2012

    Rails 3.1 is amazingly promising. Unobtrusive javascript support is amazing. It makes your life easy!!

  • greypanda | 7:13 PM September 7, 2012

    No matter which framework you choose, you are going to be in for a long learning process until you can do decent work.

    I started a project on RoR a couple of years ago, but Ruby just never felt “comfortable”.

    This year I began a rather complex application using Django, mostly because it has a built-in admin application that just saves buckets of time. I also learned the niceties of pdb.

    I was also trying to get out of the Apache jail and found that nginx and uwsgi, after a substantial learning experience, was far easier to bend to my needs than Apache.

    But you need to spend several months with any framework to get good at it. None of them are plug-and-play.

  • raj | 9:20 AM September 14, 2012

    Ruby has tons of gems. So you will have to look at that too.

    Now days web development is mostly integration of plugins/gems. All you have to focus is the business.

    For now I would recommend Rails until Django has plugins for almost everything

  • Mark | 6:21 PM September 29, 2012

    It would be great to find a similar article written by someone who’s background is Ruby/Rails and then briefly got into Python/Django for a review. Having started with Ruby/Rails, done some projects, then trying Python/Django, I found it more difficult to use Django. I spent a lot more time hunting down how to get some basic behaviors correct and not covered in the online documentation. The built-in admin is really great. But with Rails, you have a working basic app right out of the box.

    I don’t know why some posters here say Rails is flaky. I’ve never had a problem with it that I’d call flaky. If it’s acting flaky, you probably did something wrong.

    I like the fact that Rails uses Ruby as its scripting language in the web templates. Django hacks in a different language. Python classes also seem a bit hacked with all the special means of creating class methods and behaviors. In Ruby, if I need to do something, I can almost guess at a reasonable method that works. In Python, I have to hunt down the “one right way” to do something.

    OK, it sounds like I’m dissing Python/Django. Really, I do like them. It’s just that, currently, I like Ruby/Rails more. smile

  • dixon siew | 1:28 AM October 1, 2012

    In rails, the code is much more cleaner, as it doesn’t need to import many libraries as in django. In django, you will have to copy and paste the imports (django.http.*, etc) everytime you create a new urls/views

  • Tobi | 4:22 AM August 12, 2013

    Both are really cool, powerful frameworks but my personal preference is Django. I know it sounds lazy,  but I found Django to have a faster, more logical configuration and also seems to be a bit more stable, generally.  Also, as mentioned by others,  the “automagic” nature of RoR scares and fuses me a little - though, that’s probably my own shortcoming.

  • Vaclav Spirhanzl | 5:58 AM January 8, 2014

    Excellent article, thank you very much.


  • Brisbane | 5:32 PM February 16, 2014

    Thanks for a great article. As someone who doesn’t know either language, a big factor for me is that Python seems to have a much broader market outside of web development. Django it is!

Add your comment below

Remember me

Please enter the word you see in the image below:

*  Please be aware that all comments are moderated.

Interested in a particular topic?

If there are specific topics you’d like to see us discuss on our blog or other ideas you’d like to share, please let us know. Click here to contact us.