Book Image

Django 2 Web Development Cookbook - Third Edition

By : Jake Kronika, Aidas Bendoraitis
Book Image

Django 2 Web Development Cookbook - Third Edition

By: Jake Kronika, Aidas Bendoraitis

Overview of this book

Django is a framework designed to balance rapid web development with high performance. It handles high levels of user traffic and interaction, integrates with a variety of databases, and collects and processes data in real time. This book follows a task-based approach to guide you through developing with the Django 2.1 framework, starting with setting up and configuring Docker containers and a virtual environment for your project. You'll learn how to write reusable pieces of code for your models and manage database changes. You'll work with forms and views to enter and list data, applying practical examples using templates and JavaScript together for the optimum user experience. This cookbook helps you to adjust the built-in Django administration to fit your needs and sharpen security and performance to make your web applications as robust, scalable, and dependable as possible. You'll also explore integration with Django CMS, the popular content management suite. In the final chapters, you'll learn programming and debugging tricks and discover how collecting data from different sources and providing it to others in various formats can be a breeze. By the end of the book, you'll learn how to test and deploy projects to a remote dedicated server and scale your application to meet user demands.
Table of Contents (14 chapters)

To get the most out of this book

To develop with Django 2.1 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 MySQLdb bindings, or the PostgreSQL database
  • Docker Desktop or Docker Toolbox for complete system virtualization, or virtualenv to keep each project's Python modules separated
  • Git or Subversion for version control

All other specific requirements are separately mentioned in each recipe.

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.packt.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 & Errata.
  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-2-Web-Development-Cookbook-Third-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!

Download the color images

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:

# settings.py or config/base.py
INSTALLED_APPS = ( 
    # ... 
    'django.contrib.contenttypes',
) 

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

{% block meta_tags %}
{{ block.super }}
{{ idea.get_meta_tags }}
{% endblock %}

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

(myproject_env)$ pip3 install "Django~=2.1.0"

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.