Django makes web app development effortless

Django is a framework powering some of the largest websites in the world. That power is available to you to as well! Find out what makes Django great and how I got started with it.

If you’re sold on digital platforms being important to service users, you might still be wondering why learning Python fits your needs as a nurse. It’s time to talk about Django!

nurseAdvance is built on Django. It’s a web application framework, following Python-esque ideas (no, not silly walks…), which means it takes care of the basics without getting in the way by being too opinionated. To build a web application you need content, structured specifically to your purpose. The jewel in Django’s crown for this is the Object Relational Mapper (ORM), which means if you need data built to your needs, you are a handful of lines of code away from creating that structure.

To explain, we need to briefly talk about relational databases. Sorry! Imagine you’re creating an online learning platform for nursing students. Something you want to record data for is a "subject module", which will have data fields for subject, year, semester, reading list and so on. Then each reading list will have a number of different books, some of which will appear on more than one list. Then each book will have an author, publisher, edition…

This is a lot of related data and if you were to store everything under your "subject module" data model, you’d end up frequently repeating yourself and making the database increasingly unwieldy as it grows. Relational databases solve this problem by storing each entity in a separate table and defining relationships between tables. A book becomes stored once as an item in a book table, with a one-to-many relationship with reading lists, i.e. one book can be recorded on multiple reading lists, as a reference rather than being duplicated each time. In this way a reading list can “know” which books it contains, but a book can also “know” which reading lists it’s on from the other direction. This gives you great flexibility in how you ask your database to display the information you want.

What makes Django’s ORM magical is it abstracts away the difficult bits of using a relational database, leaving you making simple definitions and queries. For example, blogging with WordPress I needed to install an entire plugin just to have subtitles on articles. With Django I wrote one line of Python and the ORM does the rest:-

class BlogPostPage(Page):
    subtitle = models.CharField(max_length=255, blank=True)

If you’ve never coded a line in your life, you can still read that and understand the intent. I’ve subclassed (copied) a Page model from the content management system (CMS) I’m using, to create my customised BlogPostPage model. Then I added a field called "subtitle", set as a string of characters, with a maximum length and allowed it to be optional rather than required. Behind the curtains Django's ORM will make the necessary adjustments to the database. Not so hard, eh?

In this way you can shape your data models in very plain language, which is incredibly powerful. Your data defines the foundation of whatever application you’re creating and Django makes it so simple as to genuinely be fun to play with!

There’s more to Django than the ORM, it covers a lot of basic functionality for you, like user authentication and browser security, along with nice extras like RSS feed generation. For what it doesn’t cover, there’s a vibrant community of coders making extensions. But the ORM is the key, because shortly after finishing a few tutorials you will be free forever more to create robust, customised solutions that fit your exact needs. I wasn’t kidding about the online learning platform, it’s one of several tutorials in the exceptional Django By Example book (get it, it's awesome!), because that’s how simple it is in practice.

As a practical example, the search capabilities of the online learning platform where I'm studying appear to be almost entirely missing, leading to frustration amongst students looking for half-remembered information, long after a lecture. If it were my Django code, just with the brief learning I’ve done I could implement a high quality search engine like ElasticSearch or Solr. And so could you. Problem solved!

Want to try it out? Once you’ve installed Python and PyCharm the best place to start is with the official tutorial, which is easy to follow and covers a lot. Then get Django By Example and build out the tutorial projects. Or the fab CodingEntrepreneurs channel has a series of projects to follow along with on Youtube. After that you’ll know enough to build a wide range of custom web applications and the value you get will only be limited by your imagination!

Oh and you’ll need a server to deploy on, but that’s a topic that'll have to wait for another day.