Book Image

Django 3 Web Development Cookbook - Fourth Edition

By : Aidas Bendoraitis, Jake Kronika
Book Image

Django 3 Web Development Cookbook - Fourth Edition

By: Aidas Bendoraitis, Jake Kronika

Overview of this book

Django is a web framework for perfectionists with deadlines, designed to help you build manageable medium and large web projects in a short time span. This fourth edition of the Django Web Development Cookbook is updated with Django 3's latest features to guide you effectively through the development process. This Django book starts by helping you create a virtual environment and project structure for building Python web apps. You'll learn how to build models, views, forms, and templates for your web apps and then integrate JavaScript in your Django apps to add more features. As you advance, you'll create responsive multilingual websites, ready to be shared on social networks. The book will take you through uploading and processing images, rendering data in HTML5, PDF, and Excel, using and creating APIs, and navigating different data types in Django. You'll become well-versed in security best practices and caching techniques to enhance your website's security and speed. This edition not only helps you work with the PostgreSQL database but also the MySQL database. You'll also discover advanced recipes for using Django with Docker and Ansible in development, staging, and production environments. By the end of this book, you will have become proficient in using Django's powerful features and will be equipped to create robust websites.
Table of Contents (15 chapters)

To get the most out of this book

To develop with Django 3.0 using the examples in these pages, you will need the following:

  • Python 3.6 or higher
  • The Pillow library for image manipulation
  • Either the MySQL database and the mysqlclient binding library, or the PostgreSQL database with the psycopg2-binary binding library
  • Docker Desktop or Docker Toolbox for complete system virtualization, or a built-in virtual environment to keep each project's Python modules separated
  • Git for version control
Software/hardware covered in the book OS recommendations

Python 3.6 or higher
Django 3.0.X
PostgreSQL 11.4 or higher/MySQL 5.6 or higher

Any recent Unix-based operating system, such as macOS or Linux (although it is possible to develop on Windows too)

All other specific requirements are mentioned separately in each recipe.

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copy/pasting of code or incorrect indentation.

For editing project files you can use any code editor, but we recommend PyCharm (https://www.jetbrains.com/pycharm/) or Visual Studio Code (https://code.visualstudio.com/).

I would be thrilled if, after successfully publishing your Django project, you would share your results, learnings, and outcomes with me by email at [email protected].

All code examples have been tested using Django 3. However, they should work with future version releases as well.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the Support tab.
  3. Click on Code Downloads.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Django-3-Web-Development-Cookbook-Fourth-Edition. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "For this recipe to work, you will need to have the contenttypes app installed."

A block of code is set as follows:

# requirements/dev.txt
-r _base.txt
coverage
django-debug-toolbar
selenium

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

class Idea(CreationModificationDateBase, MetaTagsBase, UrlBase):
title = models.CharField(
_("Title"),
max_length=200,
)
content = models.TextField(
_("Content"),
)

Any command-line input or output is written as follows:

(env)$ pip install -r requirements/dev.txt

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "We can see here that the upload-related action buttons are also replaced with a Remove button."

Warnings or important notes appear like this.
Tips and tricks appear like this.