The Django Framework's Killer Feature for Java Developers
Since Struts dominated the Java Web development landscape a decade ago, a competition began to replace it with something more productive. In addition to the Spring Framework and JavaServer Faces (JSF), an explosion of Java Web frameworks such as Wicket, Stripes, GWT, Play and Click has given Java developers a bewildering array of choices.
Outside of the Java world, the dynamic language ecosystem has produced its own Web frameworks such as Ruby on Rails and Django to name a couple. However, because of their "is not Java" or "does not run on the JVM" limitations, Java shops almost always ignore them.
Django, however, has such a specific feature set that is so symbiotic with the type of business applications many Java developers develop every day that it deserves special attention. Specifically, Django has a killer feature that makes it worthwhile for Java shops to leave the comforts of the Java language: its automatic admin interface.
What Is the Django Admin Interface?
Django is built around the idea of reusable modules (simply called "apps") that can be assembled into a larger application. One of these apps is the Admin interface, basically an auto-generated UI for listing/searching/filtering database entities and creating the add/edit/delete screens for them.
Many frameworks claim to offer something along the same lines (e.g., Ruby on Rails), but none of them are truly production-ready out of the box. This is the big difference with Django Admin: you can deploy it as-is without any customizations and it would probably be more feature-rich, slick and polished than your hand-coded CRUD screens.
The productivity boost you get from this out-of-the-box usability is incredible. You stop thinking in terms of HTML forms or templates and start thinking instead at a much higher lever:
- What database entities do I want to show?
- What fields should be visible on the search screen?
- Which of them can be used as filters?
- What fields should be visible on the add/edit/delete screen?
As an example, when I initially started learning Django I developed a working CRUD portal for about 10 database entities in about 5 days -- and that included brushing up on Python and doing a few Django tutorials. More importantly, I completed this project by writing a single line of HTML (no boring
<tr/> tags, etc.). I later attempted to do the same thing in the latest version of JSF 2, but it was like being forced to crawl after I had already learned to run. I promptly went back to Django.
In this article, I'll show you the Django automatic admin interface in action. We will build a simple invoicing application with four entities: Customer, Product, Invoice and Invoice Line. Invoice consists of a master-header relationship between an Invoice Header and Invoice Line.
Installing Python and Django
On Ubuntu, it's as simple as this:
sudo apt-get install python-setuptools sudo easy_install Django
When you have done all of that, just do the following from the app folder:
./manage.py syncdb ./manage.py runserver
The first command auto-creates the database tables in the local SQLite3 database. The second one runs the app on port 8000.
Page 1 of 2