Django 2 Web Development Cookbook - Third Edition

Book description

Create unbelievably fast, robust and secure web apps with Django Web Framework and Python 3.8

Key Features

  • Discover solutions to a variety of web application scenarios, leveraging the power of the Django framework
  • Understand URL routing, models, forms, templates, and RESTful services with Django 2.14
  • Test, deploy, and scale your web applications efficiently with Amazon Web Services

Book Description

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.

What you will learn

  • Get started with the basic configuration necessary to start any Django project
  • Build a database structure out of reusable model mixins
  • Secure web applications against malicious usage and address common performance bottlenecks
  • Integrate with, and extend, the Django CMS
  • Construct and manage complex and deep hierarchies
  • Import data from local sources and external web services and export it to third parties

Who this book is for

This book is designed for Python developers working on fast and secure web apps that can scale over time. You'll also find this book useful if you want to upgrade to latest Django framework. A background in Python 3 along with basic knowledge of the Django framework will be useful.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Django 2 Web Development Cookbook Third Edition
  3. Dedication
  4. Packt.com
    1. Why subscribe?
    2. Packt.com
  5. Contributors
    1. About the authors
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Get in touch
      1. Reviews
  7. Getting Started with Django 2.1
    1. Introduction
    2. Working with a virtual environment
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Creating a virtual environment project file structure
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Working with Docker
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Creating a Docker project file structure
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Handling project dependencies with pip
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Including external dependencies in your project
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Configuring settings for development, testing, staging, and production environments
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Defining relative paths in the settings
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    10. Creating and including local settings
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    11. Setting up STATIC_URL dynamically for Subversion users
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    12. Setting up STATIC_URL dynamically for Git users
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    13. Setting UTF-8 as the default encoding for MySQL configuration
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    14. Setting the Subversion ignore property
      1. How to do it...
      2. How it works...
      3. See also
    15. Creating the Git ignore file
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    16. Deleting Python-compiled files
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    17. Respecting the import order in Python files
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    18. Creating app configuration
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There is more...
      5. See also
    19. Defining overwritable app settings
      1. Getting ready
      2. How to do it...
      3. How it works...
  8. Database Structure and Modeling
    1. Introduction
    2. Using model mixins
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Creating a model mixin with URL-related methods
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Creating a model mixin to handle creation and modification dates
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Creating a model mixin to take care of meta tags
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Creating a model mixin to handle generic relations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Handling multilingual fields
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Enabling schema microdata enhancements
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Using migrations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    10. Switching from South migrations to Django migrations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    11. Changing a foreign key to the many-to-many field
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  9. Forms and Views
    1. Introduction
    2. Passing HttpRequest to a form
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Utilizing the save method of the form
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Uploading images
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more
      5. See also
    5. Creating a form layout with custom templates
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Creating a form layout with django-crispy-forms
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Filtering object lists
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Managing paginated lists
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Composing class-based views
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Generating PDF documents
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    11. Implementing a multilingual search with Haystack and Whoosh
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  10. Templates and JavaScript
    1. Introduction
    2. Exposing settings in JavaScript
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Arranging the base.html template
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Using HTML5 data attributes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Providing responsive images
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Opening object details in a modal dialog
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Implementing a continuous scroll
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more
      5. See also
    8. Implementing the Like widget
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Uploading images via Ajax
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  11. Customizing Template Filters and Tags
    1. Introduction
    2. Following conventions for your own template filters and tags
      1. How to do it...
      2. See also
    3. Creating a template filter to show how much time has passed since a post was published
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Creating a template filter to extract the first media object
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Creating a template filter to humanize URLs
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Creating a template tag to include a template if it exists
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Creating a template tag to load a QuerySet in a template
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Creating a template tag to parse content as a template
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Creating a template tag to modify request query parameters
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  12. Model Administration
    1. Introduction
    2. Customizing columns on the change list page
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Creating admin actions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Developing change list filters
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Customizing default admin settings
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Inserting a map into a change form
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  13. Security and Performance
    1. Introduction
    2. Making forms secure from Cross Site Request Forgery (CSRF)
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Implementing password validation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Downloading authorized files
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Adding a dynamic watermark to images
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Authenticating with Auth0
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Caching the method return value
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Using Memcached to cache Django views
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Using Redis to cache Django views
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  14. Django CMS
    1. Introduction
    2. Creating templates for Django CMS
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Structuring the page menu
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Converting an app to a CMS app
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Attaching your own navigation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Writing your own CMS plugin
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Adding new fields to the CMS page
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  15. Hierarchical Structures
    1. Introduction
    2. Creating hierarchical categories with django-mptt
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Creating a category administration interface with django-mptt-admin
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Rendering categories in a template with django-mptt
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Using a single selection field to choose a category in forms with django-mptt
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Using a checkbox list to choose multiple categories in forms with django-mptt
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Creating hierarchical categories with django-treebeard
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Creating a basic category administration interface with django-treebeard
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  16. Importing and Exporting Data
    1. Introduction
    2. Importing data from a local CSV file
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Importing data from a local Excel file
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Importing data from an external JSON file
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Importing data from an external XML file
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Creating filterable RSS feeds
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Using Tastypie to create an API
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Using Django REST framework to create an API
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  17. Bells and Whistles
    1. Introduction
    2. Using the Django shell
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Using database query expressions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Monkey patching the slugify() function for better internationalization support
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Toggling the Debug Toolbar
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Using ThreadLocalMiddleware
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Using signals to notify administrators about new entries
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Checking for missing settings
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  18. Testing and Deployment
    1. Introduction
    2. Testing views with mock
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Testing APIs created using the Django REST framework
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Releasing a reusable Django app
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Getting detailed error reporting via email
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Deploying on Apache with mod_wsgi
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Setting up cron jobs for regular tasks
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  19. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Django 2 Web Development Cookbook - Third Edition
  • Author(s): Jake Kronika, Aidas Bendoraitis
  • Release date: October 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788837682