It is very confusing for developers to decide which framework is best for their projects and choosing which one to learn can be a real challenge facing newbies to modern frameworks. After working in three (Django, Laravel and rails - otherwise known as ruby on rails) frameworks, I am comparing these great frameworks on the basis of their motto, ease of learning, performance, strength & weakness of libraries and templates, support, future scope, job chances, cost and maintenance. If you don’t know what frameworks are then read this post Introduction to Frameworks.
NOTE: The people who like their own framework are criticizing the weakness of their favorite framework. I cannot help this because fact is fact. Each framework has some advantages along with some disadvantages.
Programming language: The first major difference between these frameworks is that django is in python, laravel is in PHP and rails is in ruby. If you are going to use any of these frameworks then you will have to learn it's language. So due to this restriction many developers choose frameworks which match with their language knowledge. It is not hard to switch from one language to another but it does take some time. If you are confused about languages then here is the comparison of these languages - PYTHON vs PHP vs RUBY.
Motto: All of these frameworks are MVC frameworks and the motto of all these frameworks is ‘don’t repeat yourself‘, i.e. reusability and portability. These all are free, open source projects.
Also see CMS vs MVC frameworks.
The people who raise the point that Django is MTV rather than MVC, please read this article. Django is much MTV, but it is MVC because the framework itself handles the controllers.
Websites: Some well-known sites that use Django include Pinterest, Instagram, Mozilla, The Washington Times, Disqus, the Public Broadcasting Service, and Bitbucket. Laravel is a new framework with an initial release in June 2011. After its release it became very famous. Some websites in laravel are Deltanet Travel, Sublimity, Neighborhood Lender, Sendity and MyRank. Rails is a great framework and some of the top websites using rails are Twitter, Shopify, SoundCloud, Heroku, Github, Bloomberg and Hulu.
2. Ease of learning:
Although all three have great community and official documents, learning Django and Laravel is much easier than rails. The offline docs for Django makes it the easiest. If you are from a PHP background, then you can learn Laravel within just two to three weeks. The official docs are here: django docs, laravel docs and rails docs. Here is django offline pdf.
Security: All three have great security if the developer doesn’t make any mistakes. Django has middlewares, rails have active records and Laravel has HTTP Middleware. All three also provide csrf tokens for forms. There is no big security difference in these frameworks. It all depends on the experience of the programmer.
UPDATE: I noticed some readers point out that programmers are humans and they will make mistakes. In response to that, I will say that Django is the most secure and Laravel is the most unsecure. Read this article for django security. Here is the Rails security guide. And here is the laravel security guide. I will again state that there is no framework which is fully secure because framework developers as well as hackers are also humans. You can increase security but cannot make it 100% secure. If you write code very carefully, then all frameworks are the same for you in terms of security.
Update on Speed: Some people had objection when I wrote Django is faster than Laravel because of Python. They are right as speed depends on code complexity and developer's skill to handle this complexity. As a Django lover, being biased towards Django was unfair. So I am removing this line. This section is most controversial part of my article and this is obvious thing. Every developer chooses best framework and we have millions of developers for each framework. It implies that there is no clear day and night.
Time required to make an app: If you have a perfect understanding of the framework then making an application in rails is fastest as it provides many shortcuts and you have to write much less code. On other hand, Laravel development is slowest and does not provide such a strong library (strong relative to Django and Rais). With Laravel you have to write much more code which may cause some confusion and there will be a greater tendency for errors.
4. Strength & Weakness of library:
Common things in all frameworks:
- All are MVC (Django is also called MTV but just the name is changed, the concept is the same).
- All frameworks focus on readability and simplicity of code and files distribution.
- All do auto queries for databases. We do not have to write database queries directly.
- All automatically build tables in the database from models.
- All frameworks have easy and secure routing systems. The webpages are rendered dynamically.
- All have their own template systems and each template system is rich in filters and pre-defined functions. There is only difference in the syntax. See blade template in laravel.
- These all are flexible and portable with other modern technologies.
Django has a very powerful library with following features:
- The built in admin section, decorators and view classes are the strength of Django
- The auto-generated forms for models with validation makes it very easy
- A caching framework which can use any of several cache methods.
- Support for middleware classes which can intervene at various stages of request processing and carry out custom functions.
- An internal dispatcher system which allows components of an application to communicate events to each other via pre-defined signals.
- An internationalization system, including translations of Django's own components into a variety of languages.
- A serialization system which can produce and read XML and/or JSON representations of Django model instances.
- An interface to Python's built-in unit test framework.
- An extensible authentication system.
- The dynamic administrative interface.
- Tools for generating RSS and Atom syndication feeds.
- A sites framework that allows one Django installation to run multiple websites, each with their own content and applications.
- Tools for generating Google Sitemaps.
- Built-in mitigation for cross-site request forgery, cross-site scripting, SQL injection, password cracking and other typical web attacks, most of them turned on by default.
- A framework for creating GIS applications.
Laravel's libraries are not as strong as Django and Rails but are sufficient for making any kind of website.
Also see Laravel framework architecture.
- Bundles and composer provide several bundle modular packaging systems and dependencies.
- Routing - The easiest to manage and abstract way of routing. It just makes everything hassle free, and the abstraction provided takes out each and every complexity.
- Eloquent ORM support - Another service provided to abstract and automate the model part. Relationships and mapping of a database with our application with a simple convention over configuration technique.
- Migrations - A way to version our database scripts in a much more elegant manner. No need to keep all the checks on migrations. A team working on a project can just pull the given migration, and all is set and ready to go.
- Queue management - To abstract the unnecessary tasks and get them queued behind the scenes and make user response time much faster.
- In-house support for Redis. It can also be extended to memcached.
- Dependency Injection - Easy testing and automating dependency loading
- Artisan - Making command line apps in a moment
Learn Laravel using Laravel 7 tutorials.
- Ruby on Rails includes tools that make common development tasks easier "out-of-the-box", such as scaffolding that can automatically construct some models and views needed for a basic website. Also included are WEBrick, a simple Ruby web server that is distributed with Ruby, and Rake, a build system, distributed as a gem. Together with Ruby on Rails, these tools provide a basic development environment.
- Active record: It plays a major role in rails applications. It is more magical than Eloquent ORM in Laravel and models in Django.
- Shortcuts: Those people who come from other programming languages or frameworks consider it to be a magical framework due to a lot of shortcuts. Most of the things are pre-defined and you have to write only a few lines of code to make a complex application.
- Auto routing: Some common functions on database tables like create, edit and show are automatically defined. It means that we do not have to spend any time on simple work and we can spend longer on the complex parts of the project.
- Command line: A lot of things can be done by command line like using rake. Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility 'make', and uses a 'Rakefile' and .rake files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other.
- The ActiveModelHelper module contains helper methods for quickly creating forms from objects that follow Active Model conventions, starting with Active Record models.
5. Hosting Services:
You can run any application on a VPS or dedicated hosting service. Here are some links to some websites which allow you to host your project for free or on their shared hosting plans.
Some of the websites which host the Django projects are WebFaction, PythonAnywhere, Heroku, Digital Ocean, Bulehost, Dreamhost, Arvixe and Google App Engine. Here is a comparison of the last four of these hosting services Cheap Django Hosting.
6. Other Criteria:
All three are good frameworks so future scope, job chances, cost and maintenance are almost the same. Rails has some advantages over Django and Laravel in terms of jobs, although Laravel is growing rapidly.
You can take any of these frameworks according to your programming language and experience. If you are here to decide which one you should learn, then my preference is for rails. It is hard to learn but very comfortable during application making. If you want some easy stuff with a lot of features, then choose Django. The python syntax and its models make it an amazing choice. Django will take time but it is not harder than rails. And lastly if you are from a PHP background or want to learn very fast then choose Laravel.