Web development frameworks – part 4 : Django

This is a part of my web frameworks review series. Check it out if you haven’t already.

Moving on to Django, the Python based all star.

Django was created by the folks at the Lawrence Journal-World and released to the public in 2005. It’s very active and with a strong group of followers, the framework is currently in it’s 1.4 incarnation, and the last release was done in March/2012.

For the purpose of this review I used Django 1.4 and Python 2.7 on a Fedora 17 based workstation. It’s worth noting I’m almost a complete newbie both in Python and Django, to learn my way around I followed the official Django tutorial.

Install the framework in a development workstation

Both Python and Django were provided by my linux distribution on the built-in repositories, so all I had to do was pull them using yum and was good to go. Easiest installation so far!

Setup a development environment using a free IDE, application server and database

Any text editor will do, I use Sublime Text 2, but your choice won’t really affect your projects structure or how to develop them.

Develop the “Hello world” or similar sample outlined by the frameworks tutorial

The tutorial walks you through the creation of a web polls app, with user and admin front-ends. It actually starts with the admin section (since Django auto-generates most of it) so it’s not your typicall “1 min to get a Hello World! app tutorial”, but it’s easy to follow and probably better aligned to a real world app than a page that just says something :P

Anyway, the first steps into the framework are simple enough to follow, even by someone who has never developed in Python before.

There is some stuff I find a little more complicated than necessary. Take the URL configuration for example. The tutorial suggests using the following snippet as URL configuration basis:

urlpatterns = patterns('',
    url(r'^polls/$', 'polls.views.index'),
    url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
    url(r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
    url(r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
    url(r'^admin/', include(admin.site.urls)),
)

Compare this to a feature equivalent routes configuration in Play Framework:

GET     /forms/:id            controllers.Forms.index(id: String, page: java.lang.Integer = 1)
GET     /forms/:id/:page      controllers.Forms.index(id: String, page: java.lang.Integer)
POST    /forms                controllers.Forms.save()

I get it that a regular expression is more powerful, but the toll on readability and ease of use is not worth it imho. The Django version just looks messy compared to Play or Ruby on Rails.

Modify the sample app to perform a specific database query over a custom structure and display the results

Writing raw SQL in Django is quite simple, extremely simple actually if your query returns something that you can map to one of your model entities. If not, you still have the option to execute a custom SQL Sentence and iterate over it’s results in a cursor based fashion.

Add a dependency to a third party library and perform a computation using it in our app

Pluggable components in Django are called applications, you can find a repository at Django Packages. Including an app in your site is not complicated though the “feeling” I got is that they tend to get a little more coupled with the site than Java libraries (JARs) or Ruby Gems.

Develop a “Hello world” REST service

Even though Django is not as REST oriented as Rails or Play, developing a REST service is just as simple as a “human readable” one. I took the polls list view from the tutorial sample and converted it to a service returning a JSON formatted output in a few seconds, basically changing:

return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list})

to

return HttpResponse(serializers.serialize('json', latest_poll_list))

Consume our own service from our app

Python itself provides libraries that allow you to consume a REST service and decode it’s output, to try it out I used urllib2 and json.

The API is what you would expect of it, get your data from an HTTP resource and then feed it to the JSON parser to obtain a key/value matrix.

Evaluation

Learning curve: MEDIUM

Getting started with Django is not hard at all, and I bet that if you are familiar with Python it’s even easier. But in my opinion the learning curve of Django is steeper than RoR and Plays, while providing similar framework capabilities and goals.

Development performance for simple tasks: MEDIUM

Same argument as before, using Django is easy enough, but its not as easy as other frameworks. The code you write is not as simple as you would want, and the development mechanics doesn’t feel quite so fluid.

Development performance for complex/singular tasks: GOOD

Doing custom stuff feels natural in Django. Python is a very powerful language with tons of libraries, and using them from your app is completely friction-less.

Dependency management: MEDIUM

The Django project names it’s reusable components “apps”, you can find a bunch at Django Packages. Using an app within your project is not hard, but it feels a little more coupled than it should.

Additionally, the apps handling and versioning system lacks (or at least I couldn’t find them) some features you grow accustomed to if you come from RoR Gems or Maven in the Java world, like automatic version handling, deployment management, profiles, etc.

Code performance/security tuning capabilities: TBD

Coming from a Java background I always feel reluctant in the sight of non-VM backed applications, because in my experience they usually tend to be harder to tune in terms of performance and escalability.

Nonetheless, I would prefer to have some real life experience deploying Django and Python based apps into production before passing judgment on this point.

Platform escalation/redundancy capabilities: TBD

Check out the previous item, exactly the same happens here to me.

Acceptance in corporate markets: BAD

Python usually rings more bells in corporate IT environments than Ruby, but it still has a lot of road ahead to be accepted as a viable framework to develop and deploy mission critical web applications. Right now in the corporate mindset Python is a nice little scripting language, good to write backup scripts and even some harmless internal web app, but not the corporate e-commerce or home banking solution.

Complexity of developing and consuming SOAP and REST services: GOOD

Not much to add here to what I already said before, it’s simple to both provide and consume web services from Django. Python provides the basic tools and they are not hard to use at all.

TL;DR

Django is a good and solid web framework, but honestly it doesn’t bring to the table anything to make it a better choice than Ruby on Rails or Play. Having said that, it works, its fast and its easy, so if you are seasoned in Python or want to be, then by all means don’t hold back and use Django.

In terms of our internal evaluation, Django is neither a better choice than other frameworks, nor is it accepted in corporate markets to be a marketing added value.

Reference: Web development frameworks – part 4 : Django from our JCG partner Ricardo Zuasti at the Ricardo Zuasti’s blog blog.

Related Whitepaper:

Software Architecture

This guide will introduce you to the world of Software Architecture!

This 162 page guide will cover topics within the field of software architecture including: software architecture as a solution balancing the concerns of different stakeholders, quality assurance, methods to describe and evaluate architectures, the influence of architecture on reuse, and the life cycle of a system and its architecture. This guide concludes with a comparison between the professions of software architect and software engineer.

Get it Now!  

Leave a Reply


four − 1 =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books