a short view on Django compared to CakePHPphp

31 08 2008

I’m trying to get the difference between Pythons Django and CakePHP but iam more than depressed how many people (especially from the Django base) don’t like PHP at all (or make fun of it). I thought that there might be a good reason for it and compared the Frameworks against each other and mainly found out that most difference’s are just „small stuff“.

To compare this both Frameworks is quite easy. Both started nearly at the same time and try to reduce the „dont repeat yourself“ factor. Django and Cake both use a MVC (Model View Controller) like structure to reach this goal.
Both support Database Abstraction (Mainly both support the really important Databases -> Postgres and MySQL).

The Strength of Django is the smart Query generation. This is defiantly something CakePHP needs to work on. Testenviorments / Ajax / buildincompontents are the strength of CakePHP. Django should get rid of real html tags and replace them with functions. The Code looks cleaner in PHP to me (cause i like to have all information at one place), but i think bad formation of the code can annoy a lot of people which have to program with someones else code. The use of forming ARRAY’s is essential if you want to use clean CakePHP code.
Lets Talk about something damn important for Programmers -> Documentation. The good point on Django, is they have already a book out (even if they dont have a final release yet, but there will be a stable version soon. Only some days to go). Cakes documentation is really good, they just rewrote it and some parts are still missing. But you will find everything quite fast if you just get the main structure of the documentation. Djangos documentation is a bit under this but still really good to use. Cake has got a strong focus on the community behind it. With „the bakery“ and „CakeForge“ they give the users a easy access to all source people just produce. Thats something Django needs to work on.

Project Language Ajax MVC framework Push/Pull i18n & l10n? ORM Testing framework(s) DB migration framework(s) Security Framework(s) Template Framework(s) Caching Framework(s) Form Validation Framework(s)
CakePHP PHP Yes, Prototype, script.aculo.us Yes, Active record pattern Push Yes, Development branch Yes, Active record pattern Yes, Unit Tests Yes Yes, ACL-based Yes Yes, Development branch Yes
Django Python Yes Yes Push Yes Yes, Django ORM, SQLAlchemy Yes No (plugin exists, might be merged into trunk when more stable and feature complete) Yes, ACL-based Yes Yes Yes

One Reason why the Cake looks a bit cleaner to me is for sure the View Design. Its a bit more straight forward. Django does this on a more old fashion view. This makes it easier to new persons, but if you really want to separate the view to „designers“ it is cleaner to use Cake.

django view Cake view

{% if form.errors %}
Your username and password didn't match. Please try again.
{% endif %}
{{ form.username.label_tag }}: {{ form.username }}
{{ form.password.label_tag }}:{{ form.password }}

echo $form->create('User', array('action' => 'login'));
echo $form->input('username');
echo $form->input('password');
echo $form->end('Login');

Most important stuff can be found in CakePHP directly. Some important things need to be loaded for Django (like mptt) but therefor django got a „instant server function“ which can be loaded for CakePHP in additional (cakephp-instaweb). So both Frameworks have got software which need to be loaded if you want to use it for the most common needs.

Final Words:
CakePHP and Django are both good Frameworks. I think its mainly a question of what your settings for the final Product are. If you need to work with a normal provider (no vhost or something) django is out of that business. mod_python is only rarely spread yet, and to start a real server process is most of the time not possible.
If you don’t want to change a lot djangos generic views and Cakes scaffoldering both are great, but i don’t like totally preconfigured templates at all so i dont really care about them.

If you need the performance and got enough time and admin rights Django is the correct choice.
If you need to code faster, and dont want to do everthing on your own, CakePHP is the right choice.

Overall, there is only one bad choice -> to ignore a good framework at all. As long as you use a good framework you will produce code with a much better structure while you save hours. The Stepback to a non Framework based development is the only wrong decision. And after all, both are just copies of „Ruby on Rails“.


after testing a bit more with django and postgres i found some „leaks“ in definition. If you use PostGresql with Django the default table defintions (auth etc) wount generate correct OIDS for PostGres. In fact postgres dont need them, but only if you are sure that there are never 2 entries with the same value. For MySQL users this is no problem, cause with mysql you can delete the entry by using LIMIT 1 for the DELETE command. Postgres needs a sessified OID to do so. So if someone explicit does crappy things with the database -> the default Django design would be wrong and have to be altered.

And just cause many think its a feature that they have to use instat of apache webserver -> Django explicity tells you to not use the internal webserver for a productiv enviroment. Thats what they tell use about it:

Now’s a good time to note: DON’T use this server in anything resembling a production environment. It’s intended only for use while developing. (We’re in the business of making Web frameworks, not Web servers.)

And some Statistics from google where red is CakePHP (keyword : „cakephp“) and Blue is Django (keyword: „Django python“ otherwise the musicartist will be counted eiter)

just to come clear about this image: it should not display A is better than B, but it should give a view on popularity (one big fact is that PHP is more public than python, which is not the best descission). But the Graph can be a indicator for available addons / support by irc and all other community related issues.

Django is more or less deprecated. The projected has bean moved into other projects…




10 responses

1 09 2008

Actually Django is not a Rails clone. It’s just MVC framework.

1 09 2008

Once one of the developers of django got the question -> why should we use django instead of Ruby on rails and his answer was quite simple -> cause its written in ruby. I think the main difference is the amount of time they chould spend on developing django. If you gave them enough time it will be as feature rich as ruby on rails (if they get enough good respons on django, what will be quite sure)

3 09 2008
gustav krager

ich antworte dir auf deutsch. Danke fuer deinen Vergleich, sonst wird immer mit Rails gebashed 🙂

Nur eines vorneweg ich kenne Cake nur sehr wenig (1 Projekt gemacht), Django aber besser. Meine background ist seit 2002 ein Webdeveloper zu sein und die meisten Jahre davon mit PHP und seit gut 2 Jahren nun mit Django.

„If you need to code faster, and dont want to do everthing on your own, CakePHP is the right choice.“ Das geht mit Django aber auch 🙂
Ich halte zwar nichts davon, aber ich habe mal einen Blog gelesen das einer fuer ein Cake Projekt doppelt soviele Zeilen gebraucht hat wie bei einen Django Projekt.

Du hast auch vergessen zu erwaehnen das das langweiligste an Webentwicklung, der Admin Bereich sofort in Django zur Verfuegung steht.

Tests gibt es in Django und wenn man sich mit Unittests etwas auskennt ist das auch simple Python hat auch ein eigenes feines Testsystem doctests.

Das der Code reiner ausschaut liegt auch vielleicht daran das du mehr PHP machst als Python. Ich hab auf die Jahre gesehen ca 80% php und 20% python gemacht und fuer mich ist jetzt schon PHP nicht mehr so schnell lesbar wie Python liegt ja auch am Konzept der Sprache.

“the bakery” & Co das gibt es natuerlich auch:

und suche mal bei google-code-projekt hosting nach Django und nach Cake du wirsd 20 mal soviel zu Djano finden.
http://code.google.com/hosting/search?q=cake vs http://code.google.com/hosting/search?q=django

Ich werde mir aber cake factory und so noch genauer anschauen. Das Plugin system ist bestimmt anders zwischen django und cake denke ich mal.

Ich bin auch froh das ich nicht gezwungen bin ein JS framework benutzen zu muessen sondern die Wahl habe so lernt man auch mehr ueber ein framework meiner Meinung.

Dann wollte ich noch fragen ob du schon je mals ein ticket gefixed hast bei cakephp?

Ueberarbeite den text auch nochmal lieber sind ja einige typos drinnen wie „trieing“ …

3 09 2008

Hey gustav,

thanks for this great comment !

in front : your right. i need to rework this article. mainly its not well formed and spelling is bad, too. i will try to get it more visual (its just so hard to do with „A is better than B because of XZY“).


about the stuff you pointed:
for sure django has most of the possibilities of cake (and in some parts a lot more, like mpeg decoding and all work which is related to direct system access). The opportunities which python has against php are more or less clear and I’m trying to see the languages on a equal level (what is maybe impossible 🙂 python wins this one without a question)
Lines of code are for sure a good indicator for measuring a framework, but it always depends on the knowledge of the person who coded with the framework. I don’t think thats its hard to mess up a page with both frameworks. Just ignore the function which are already there and your code will double. In my opinion you have to calculate in that you rewrite the pagelayout and ever box which is displayed (cause otherwise all pages of a framework would look pretty similar). So i dont care about scaffoldering and generic views that much. They are for sure a good base but in the end you need to rewrite most of the stuff to fit your needs.

About the google code pages: in fact there is a huge amount of projects which are based on / extend django. One possible reason could be that cake has got its own „cakeforge“. Ive tried the search to, and your right. With „cake“ as search term you get some pages but non of them are really related to CakePHP. I’ve tried CakePHP as search term and it was a bit bitter but still lousy.
The other possibility -> most CakeUsers rly use the cakephp.org page and nothing else (maybe because they don’t know the pages or they just don’t need them).
What i wanted to say in the article -> bring all related stuff to one page is good and i like it. Django just don’t care that much about the community pages and let them work that out alone (which is totally okay, cause most of the projects does it that way), but corporate identity and the same look and feel just let you get easier into a new page. But to say something bad about the Cake Page: The constantly Donate requests are a bit to much (okay, i’am drifting away 🙂 ).

About the Tickets-> nope, i’ve never fixed a ticket for CakePHP or for Django. This view is totally from the outside.

3 11 2008

Interesting article, I’m not really a developer by profession, but I’ve built a couple of small applications for personal use, one in cakePHP, one in Django (I’ve also had a quick mess around in Ruby on Rails, but that’s another story.
So, bearing in mind my non-developer status, and the fact that the cakePHP version I was using was an earlier one (1.18 I think), here’s my assessment:
Overall, I found the Django framework more productive. It took a little longer to get over the initial learning curve, but once you’re over that, you can build a lot of stuff very quickly. Don’t get me wrong I still like cakePHP (I built my own timesheet/invoicing app with it), but I just seemed to find throwing nested arrays around a bit fiddly. Maybe i just wasn’t using cakePHP properly…
It probably comes down to the nature of the language in the end, Python just seems to be a more object-oriented language by nature than PHP. I’m still a bit unfamiliar with Python, but I’m starting to like it
Another thing to bear in mind is Django’s history – having been born in a content-driven news-info style environment it excels at that type of task. The built in admin views and user permissions management are massive timesavers as well.
Having said all that, you have to look a little harder for your hosting provider if you want to use Django in a shared environment. I’m using Webfaction at the moment, who are a good option at the cheaper end of the spectrum ($US10 or less), and have a relatively painless setup.
You can set up CakePHP on just about any host that has PHP and SQL of some kind. This becomes important for someone like me based in Australia. Australian based Django hosting is a little costly at the moment for personal use, so I’m using the US based Webfaction and suffering the slower ping times. For my cakePHP app, I have it hosted on a super fast, super cheap Australian hosting provider, so that’s a bit of a bonus…
Anyway, it’s kind of a tough choice because they’re both good options. Personally, I just found Django more fun and more productive once I’d got over the hurdles at the beginning, but I’m thinking of taking a return tour to cakePHP to see how it’s developed over the last year.

3 11 2008

Hey Jeff,

for sure my view is influenced by my personal likes. I like to have describe all data for the query in on array instead of multiple functions. Thats against the Object Orientated Design Pattern, and i know that, but i still like array way 🙂
Its just faster to see, why the Setting XYZ is in that query.

Django has got some massive features which i rly like (SQL Alchemy) and Python is just a awesome Language (especially cause its strongly connected to the OS. So more specific tasks like ‚grab a thumbnail from a video‘ doesn’t need to „exec“ a program to do so) and thats the big plus of Django.
But as long as we don’t care that much about the language (depends on the needs of the site), its just the questions -> what does the job faster / more intuitive for yourself.
In my oppinion django is damn fast if you have a „typical problem“ (like user administration, or the comments on blog entries) but if you leave that are it feels like -> django was build to do that kind of tasks and than you need to do everthing else on your own.
Whenever i use Django, i feel forced to typical problems. If you need something changed you need to override everthing until you have rewritten the complete part which you wanted to use. Dont get me wrong, i see the effect of djangos speeding up the development, but its seems to „focused“ on this basic tasks.

And if we talk about the Admin section -> Yeh, its awesome work. It looks good and feels great to use! But if we look at CakePHP -> Doesnt Scoffoldering doesnt the same. Maybe it doesn’t look that good, but its does the same things (CRUD). The routing of the URL’s are done by just delete on char in the Route.php and with the bake command you get all files written to the file-system if you want to alter them.
Don’t get me wrong again -> the Django Admin Panel is really nice, but „is it really that awesome“, that you leave other features behind?

Without a question it’s a closeup fight between them, and so I’m really thankful for every comment with another individual opinion. (hope to get some PRO Cake voices too, but maybe Cake users don’t care enough about other solutions, what would be sad. There is no „100%“ correct answer, its all a question of likes and dislikes and topic specific).

—-zip — and just because its on my mind atm -> one big pro for django / python is mapnik (python based mapping solution). its damn good, and there is no other free solution which is that advanced (big G. solutions doesn’t count -> its not free, so its illegal 🙂 ).

and greets to Australia! Have been there 2 years ago, where if found some Django loving friends too 🙂 (they got django as a topic in the university, which is definitely a good step -> learning the basics of a language is good, but learn to use the basics productive is even better)
My youger sister does „work and travel“ in OZ atm too.

19 07 2009
19 07 2009

True, but its still a false result. it has got a huge amount of traffic befor 2005 where django didn’t exist / have not been public. The amount of searchterms is quite exactly the difference between django and cake. Google Trends is maybe not the best for that kind of research. I think a good reason for Django would be that GoogleApp is using it for there application base.
Anyway: Its like comparing languages on langpop.com the result will be differend for every special case. At least you need to check which framework does the best effect for your project. If your doing work close to the system base / where good python libs exist which you want to use, python is clearly up in front (and if you would love to develop your own libs, cause of the namespace which is done so crappy in the new php version). My tests for developing pages with Cake and Django, Cake was clearly the winner mainly because of the more complett set of functions and damn great documentation.
At the momentan iam working a lot with Java and i promis you -> CakePHP and Django are great frameworks which make the development increadible fast against some Java frameworks (but java has a damn good base for business applications).

Don’t focus yourself to much on the lang if you have a bigger project. Focus on the base of functions you want to have. Predefine your needs befor you choose the framework. If both framework fulfill your needs -> choose your prefered programming language (if performace doesn’t matter).

6 10 2009

There is a simple link to compare the trends a bit mor realistic:


Simple search not for django python vs cakephp, but against cakephp php, so you have the language embedded to both searches.

With that, you see a much more realistic result, since both can win/loose by there language.

As you can see, cakephp looses a lot by adding php, so we can guess that this is the same for django with python.

About both frameworks:
I tested alot with cakephp, and worked (after that) with django. My result: CakePHP seems to be easy, but has a lot to much Convention over Configuration, somethimes I couldn’t understand why cakephp does something. I need to remember to much logic.
Django on the other hand, while still using a lot of magic, forced me to do some important things in configs and definition which really helps me to unterstand what django does. I found it much more easy to understand complex examples in django then in cakephp.

Also, django seems to be MUCH faster then cakephp, in my tests up to 20x faster. Other benchmarks I found in the net says the same (but allways with the info: possible that there is room for a lot of optimizations in both frameworks)

6 10 2009

yeh, the php takes a lot power from the cake graph. I made another test where the lang is independet but we still are sure that its about the web frameworks:
Cake is than only slightly on top (i dont think that this rly matters). But that should be the fairest compare of both frameworks (i dont think that a lot of people will write about CakePHP and explain it more with the PHP word).

Anyway -> Performance is a key argument for sure! A possible performance leak of cake is that they use much more functions by default. Django let the programmers do more work on there own. Whats clear -> a function call does take more time than just spid out a var. i think a proper test without usage of functionfields and scaffoldering would make this difference much smaller.
Okay, functions cost performance, BUT they do a lot for you and your fast development. If you want to have insane performance you leave out any framework (except a SOA or cacheing framework). We get now in a fine granulated state -> what do we want to have from a framework. performance over lazyness? how heavy is this impact to the project. should we comepile the project as binary? which ORM methode works best and most effectiv.
I think that performance strongly depends on lazyness for the programmer. You can tweak everthing away if you want to but than you loose again the maintainability. More abstract less performance. Iam unsure if cake make use of the new namespace function from php. I dont think so, but thats another point which defently makes PHP a not so good choice. i seriously love python, but in my oppinion abstraction over performance (and in the normal world -> python is much better for abstract structures than php).

Its a bit like the Assembler discussion. People who did a lot with it, would only move slowly to a more abstract language, cause they miss performance. This argument is always valid, but never without loosing maintainability.
And than we got the „how low do i have to go“ question. Do i need to programm the HTML response by myself to get rid of the Apache? The answer is NO! Performance is important but not with the risk to loose security / reduce stability.

About the Convention over Configuration ->
Thats the best if you need to work in a team. Without a question its harder to understand in detail, but the reusability is awesome (even if the creator is not that good). If the „eat your own dogfood“ (use what you have written once, even if you dont like it anymore. And if you dont like it anymore -> redo this part until its okay again) rule is done refactoring will be the next step until the component reach a level which is good enough to be used in all projects.a

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:


Du kommentierst mit Deinem WordPress.com-Konto. Abmelden /  Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )

Verbinde mit %s

%d Bloggern gefällt das: