Setting Up Django with DRF
In 2003, the Django project was started by developers Adrian Holovaty and Simon Willison from World Online, a newspaper web operation company, and was open sourced and first released in the summer of 2005. When Django was first built, the world was still using dial-up modem internet connections, mobile devices were still not popular, smartphones didn’t see the daylight, and people would access web pages through their desktops and laptops. Django was the perfect framework that had all the features needed to build a web application for that age.
Over the last two decades, technology has evolved drastically:
- We have moved from dial-up internet connections to 4G/5G internet connections
- 55% of the world’s internet traffic came from mobile devices in 2022 (https://radar.cloudflare.com/)
In this book, we shall see how to build a modern web application using Django and deep dive into the core concepts that a developer should know to create a scalable web application for startups. A developer building a product for a startup is expected to be more than just a regular developer writing code in Django; they are expected to develop their code, write tests for the business logic, deploy their applications to the web, and finally keep monitoring the service they have deployed. Here, we will learn how easy it is to develop web applications with Django and the best practices that developers in the industry follow, especially in startups, to make their development cycle easier and faster.
In this first chapter, we shall learn the basics of Django and how to set up a Django project and structure the project folders. Since we shall mostly work with RESTful APIs throughout this book, we will learn about the conventions of the REST API and the crux of setting up a Django project with Django Rest Framework (DRF) for creating RESTful APIs. We shall also focus on versioning APIs and how we can implement versioning using DRF. DRF gives us the flexibility to create both functional and class-based views; we shall learn about them in this chapter, along with their pros and cons.
We will cover the following topics:
- Why Django?
- Creating a “Hello World” web app using Django and DRF
- Creating RESTful endpoints with DRF
- Working with views using DRF
- Introducing API development tools