With software now being offered as a service (i.e. online web applications, or “SAAS”), your users are increasingly expecting your software to be available anytime, anywhere, from their web browser. To meet this need, I’ve recently had a chance to work with a wonderful framework called DJango which allows you to quickly build web applications. In this article, I’ll give you a brief introduction to DJango and talk about why you might consider using it for your next project, or migrating your existing legacy applications to it.
In a nutshell, DJango is an open source framework for Python which allows you to quickly build web applications from a variety of development platforms. It’s available as a Mac/Linux package as well as for Windows. However, as with most open source offerings, you’re better off with Mac or Linux as your development environment because the packaging systems on these platforms are far superior to the “install and try” approach on Windows.
The last point is perhaps the one of the biggest benefits of DJango, as it gives you a high-level, object oriented language that abstracts away the underlying SQL database, and allows you to work with first class objects that automatically perform the database operations behind the scenes. At the same time, it allows you to also write advanced database operations using both high-level syntax or SQL expressions if required, and you can implement very complex logic in just a single line of code. This is a much different environment from the old days where SQL statements had to be embedded in code as strings, sent to the server, and the results manually stuffed into client‑side objects, which could easily get out of sync with the server as changes were made during development.
This object oriented interface, in conjunction with the fact that everything is server side, is a huge benefit because it keeps the business logic on the server, leaving the web browser to act solely as a user interface for your users. This, along with the fact that the project is SAAS means you never need to redeploy applications when need logic is added or changed.
Of these elements, the models are of particular interest because DJango includes a feature called “migrations” which generates the database from the models and provides facilities to keep the two in sync. Basically it generates some code which describes the instructions necessary to add, update, or remove the appropriate elements in the database so that they match your model in code. Whenever you make a change to your model, you run a migration and the database structure is magically updated to match. And since these instructions exist as mini code modules, they can (and should) be checked in along with the rest of your code so that you have the complete history of how your database was constructed and modified throughout the development process. This also makes it easy to rollback changes if required.
DJango’s documentation is also excellent and like many open source projects, is arguably better than that found in many corporate offerings. The layout is simple and the focus is on getting started quickly, whilst also providing excellent reference materials. The only weakness is that many of the examples don’t show you which modules you need to import in order to utilize certain types, so this is one area that needs a lot of improvement.
One final notable feature of DJango is that includes the tools necessary to generate a simple project to get you up and running. The generated project is also very easy to run on scaled down versions of IDE’s such as PyCharm Community edition, which is an excellent IDE for DJango projects.
So if you’re considering developing a web application, or perhaps migrating that old Windows legacy app to a SAAS offering, I recommend checking out DJango at: https://www.djangoproject.com/.