Book Image

Web Development with Django

By : Ben Shaw, Saurabh Badhwar, Andrew Bird, Bharath Chandra K S, Chris Guest
Book Image

Web Development with Django

By: Ben Shaw, Saurabh Badhwar, Andrew Bird, Bharath Chandra K S, Chris Guest

Overview of this book

Do you want to develop reliable and secure applications which stand out from the crowd, rather than spending hours on boilerplate code? Then the Django framework is where you should begin. Often referred to as a 'batteries included' web development framework, Django comes with all the core features needed to build a standalone application. Web Development with Django takes this philosophy and equips you with the knowledge and confidence to build real-world applications using Python. Starting with the essential concepts of Django, you'll cover its major features by building a website called Bookr – a repository for book reviews. This end-to-end case study is split into a series of bitesize projects that are presented as exercises and activities, allowing you to challenge yourself in an enjoyable and attainable way. As you progress, you'll learn various practical skills, including how to serve static files to add CSS, JavaScript, and images to your application, how to implement forms to accept user input, and how to manage sessions to ensure a reliable user experience. Throughout this book, you'll cover key daily tasks that are part of the development cycle of a real-world web application. By the end of this book, you'll have the skills and confidence to creatively tackle your own ambitious projects with Django.
Table of Contents (17 chapters)
Preface

Introduction

Data is at the core of most web applications. Unless we're talking about a very simple application such as a calculator, in most cases we need to store data, process it, and display it to the user on a page. Since most operations in user-facing web applications involve data, there is a need to store data in places that are secure, easily accessible, and readily available. This is where databases come in handy. Imagine a library operational before the advent of computers. The librarian would have to maintain records of book inventories, records of book lending, returns from students, and so on. All of these would have been maintained in physical records. The librarian, while carrying out their day-to-day activities, would modify these records for each operation, for example, when lending a book to someone or when the book was returned.

Today, we have databases to help us with such administrative tasks. A database looks like a spreadsheet or an Excel sheet containing records, with each table consisting of multiple rows and columns. An application can have many such tables. Here is an example table of a book inventory in a library:

Figure 2.1: Table of a book inventory for a library

Figure 2.1: Table of a book inventory for a library

In the preceding table, we can see that there are columns with details about various attributes of the books in the library, while the rows contain entries for each book. To manage a library, there can be many such tables working together as a system. For example, along with an inventory, we may have other tables such as student information, book lending records, and so on. Databases are built with the same logic, where software applications can easily manage data.

In the previous chapter, we had a brief introduction to Django and its use in developing web applications. Then we learned about the Model-View-Template (MVT) concept. Later, we created a Django project and started the Django development server. We also had a brief discussion about Django's views, URLs, and templates.

In this chapter, we will start by learning about the types of databases and a few basic database operations using SQL. After that, we will move on to the concept of models and migrations in Django, which assist in faster development by providing a layer of abstraction to facilitate database operations using Python objects.