Django unchained
Thomas Rumbold walks us through the basics of the Django Framework and Daniel Samuels show us how to get started with our first lines of code.
Thomas Rumbold walks you through the basics of the Django Framework and Daniel Samuels show you how to get started with your first lines of code.
Aweb framework (or web application framework) is a software framework that is designed to support the development of websites and online software applications – including web services, web resources and web APIs. Web frameworks aim to alleviate the overhead associated with common activities performed in web development by providing a series of tools designed to simplify and accelerate the technical development process for web developers.
So, what is Django, and what is it good for? Simply put, Django is a Python web framework designed to enable website and web application developers to build and deliver complex projects quickly, securely, and to a consistent, ‘clean’ style. It’s got a series of out-of-the-box tools that support, enhance and speed up the traditional web development process, and which help get otherwise complicated work done rapidly to a very high standard.
Django provides a series of software tools that take care of a lot of the non-project specific grunt work for a developer straight out of the box. That means that developers can spend more of their time writing the important stuff – like actual features – while lots of the mundane, standard stuff that needs to happen in the background to serve a web application is handled automatically.
“Have I heard of anything that’s built on Django?” you may be wondering to yourself. Yes, you probably have. Pinterest, the image collating website is, under the bonnet, actually a very high traffic, distributed Django system. Instagram’s web application is also written on Django. The Washington Post, The Onion, and NASA also use Django. You’re probably sensing a theme here. These guys are in charge of complicated, very high-traffic, large scale systems – and they’re all doing it pretty well (or appear to be, anyway). Bitbucket and EventBrite also run on Django (and in fact, the current EventBrite team are made up of a number of Django’s core development team).
So, what does it look like on the technical side? There’s an awful lot to Django – lots of pretty brilliant engineering under the hood, and subsequently lots of great features to use. Covering everything Django can do would be impossible for a single article (and that’s what the documentation is for) – but if you’re interested in a more general technical evaluation of how it works, you’ve generally got the following five main components to deal with.
Apps
Building features in Django typically means you’ve got to put together an app, which is designed to do a single thing, and do it very well. An app in Django is a self-contained code structure that is made up of a number of different files that usually contain everything it needs to get something done – as well as any references to other apps, if you need to share data between them. An app is made of a series of base files. You can also create new ones and import them where you think they’re necessary – but for building simple applications, the base project structure is ample.
Models
Models in Django are a mechanism to enable developers to interact with a database (doing things like creating, reading, updating and deleting) without directly touching the database layer of the stack with any of their own code. Models are what are referred to in the software world as an abstraction layer between the database and application layer – and in Django’s specific implementation, it means you almost never have to write any raw SQL – because your model is a fully accessible Python representation of your database table. That means that instead of writing a raw query, you can simply import and call elements from your model in Python, without having to go any lower down than the application layer.