How to build a Django App - Part 1: What is Django?

5 min read ⋅ 612 views

When it comes to learning web development, it can sometimes be quite difficult to know where to start. As the web grows and evolves, so too does the technology that drives it. This is partly the reason we now have so many options available as to how we can go about building a website.

First of all, it’s important to know how a website is structured. A website can be split into two parts, the front-end and the back-end. The front-end is client-side. This side is responsible for requesting pages from the server and displaying them to the user. In most cases, the browser is the client. The back-end is where the server-side programming takes place. In simple terms, this side is responsible for serving up pages.

Another way to think of it is that the code for each side runs on the corresponding machine. The server-side code runs on the server and the client side runs on the client’s device, such as a user’s PC or Smartphone.

Now that we know the main differences between the two, we can look at what languages are used to write the code of each side. When it comes to client-side, HTML, CSS and JavaScript are responsible for displaying the information we interact with.

Simple enough, however, things get more complicated when we take a look at our server-side options. The problem here is that most languages can be used for writing server-side tasks. However, just because they can be used, that doesn’t mean they should. All programming languages are different, that’s common knowledge, but because of this not all of them were created with web development in mind. This means that you could be hindering yourself using a language that might be able to do what’s needed but not in the nicest or most efficient way.

A good place to start with this is by checking if a language has a web framework. This tells you straight away that it is a good option for web development. In the past few years, JavaScript has asserted itself as one of the main players here. Although there are many controversial aspects to the language, the ability to write both the front and back ends of a website with just one programming language is very appealing to a lot of developers. It has also made significant strides when it comes to building web applications. This is made achievable through the use of its diverse range of frameworks. However, JavaScript is just one of many options and in this article, we will be focusing on an alternative, Django.

Why Django?

Django is a web framework built for Python. This language has a ton of things going for it. For starters, it’s easy to learn, can be used for Object-Oriented Programming and offers great scaling capabilities. Having Django at its disposal as well as a number of other frameworks, also make this language very flexible.

As such, it is a great option for learning server-side programming. Let’s now take a look at the advantages Django brings to the table.

Fast Development Process - Thanks to its transparent, clean code, development is usually both effective and efficient. The entire framework has been designed to help developers build an application as fast as possible. This is extremely useful for developers primarily focusing on deadlines.

Scalable - Briefly mentioned above, Django is able to meet very high traffic demands. Some of the busiest platforms use Django for this very reason. Two prime examples are Instagram and Pinterest. Sites like these have been able to weather spikes of up to 50,000 hits per second thanks to the scalability of this framework.

Versatile - Django can be used to build almost any type of website. These range from social networks and news sites, through to content management systems and wikis. It can also work with any client-side framework and deliver content in almost any format.

Secure - With the help of Django, developers are able to avoid many of the common security mistakes as the framework has been engineered to “do the right things” to protect the website automatically. For example, Django provides a secure way to manage user accounts and passwords. This method avoids common mistakes such as putting session information in cookies where it is vulnerable. Instead, cookies just contain a key. The actual password is stored in the database.

Complete - Django has a “batteries included” philosophy. By this, I mean it provides almost everything a developer might want to do straight out of the box. As everything is all a part of one product, it all works seamlessly together and follows consistent design principles. It also has up-to-date documentation.

Maintainable - Django code is written using design principles and patterns that encourage the creation of maintainable and reusable code. One particular principle it makes use of is the Don’t Repeat Yourself (DRY) principle so there is no unnecessary duplication, reducing the amount of code. The framework also promotes the grouping of related functionality into reusable apps.

Portable - As Django is written in Python, it can be run on many different platforms. This gives you freedom from being tied to a particular server platform, meaning you can run your program on Linux, Mac and Windows. It is also supported by most web-hosting providers, many of which provide specific infrastructure and documentation for hosting Django sites.

As is the case with every technology, Django is not without its negatives. The most notable problem with Django is that it evolves slowly. As such, some aspects are outdated. An example of this would be that Django uses Object-relational mapping (ORM) to help when converting complex queries. This is great, except it was created before SQLAlchemy and some now view it as inferior. The reason for this is because it is less flexible and is based on the Active Record pattern which is regarded by many as being worse than the Unit Record pattern used by SQLAlchemy. The reason for this is because, in Django, models can save themselves and transactions are off by default, so they are viewed as an afterthought. With SQLAlchemy transactional terms are thought of from the start.

What Next?

Now that we have established what Django as well as it’s pros and cons, we can begin creating websites with it. In part two, we will begin creating a simple Todo app to get used to using the framework and the various mechanics that it incorporates. 


To skip to a specific article in this series, you can use the following links. 

Part 2: Setting up the server

Part 3: Creating the database

Part 4: Creating the front-end

Part 5: Finishing the Django App



Python



MORE ARTICLES

How To Structure a Python Project

Writing programs isn’t all about the code. Sure when it comes down to it, the code is what makes the functioning program...

6634 views

Pipenv - First Impressions

Pipenv is an experimental tool with the purpose of bringing together different packaging tools in one place. It has been...

4003 views

How To Write Tests For Python

An important part of development in any Python project is testing. Testing is used to help define the intent of your cod...

2998 views