django_3_web_development_cookbook

Django 3 Web Development Cookbook

Return to Django, Django Bibliography or IT Bibliography

Fair Use Source: B084WRLDSB

See also Django 3 By Example and Django for Beginners

Bendoraitis, Aidas; Kronika, Jake. Django 3 Web Development Cookbook: Actionable solutions to common problems in Python web development, 4th Edition. Packt Publishing, 2020

Django 3 Web Development Cookbook - Actionable solutions to common problems in Python web development, Fourth Edition, by Aidas Bendoraitis and Jake Kronika

Practical recipes for building fast, robust, and secure web apps using Django 3 and Python

Key Features

Book Description

Django is a Python 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 Python virtual environment and project structure for building Python web apps. You'll learn how to build Django models, Django views, Django forms, and Django templates for your Django 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 web data in HTML5, PDF, and Excel, using and creating Django APIs, and navigating different data types in Django. You'll become well-versed in Django security best practices and Django caching techniques to enhance your Django website's web security and web speed.

This edition not only helps you work Django with PostgreSQL database but also Django with MySQL database. You'll also discover advanced recipes for using Django with Docker and Django with Ansible in Django development, Django staging, and Django production environments.

By the end of this book, you will have become proficient in using powerful Django features and will be equipped to create robust websites.

What you will learn

Who this book is for

This Django book is for Python web developers who want to build fast web apps and secure web apps that can scale over time. You'll also find this book useful if you are looking to upgrade to the latest Django 3 framework. Prior experience of working with the Django framework is required.

Table of Contents

About the Authors

  • Aidas Bendoraitis has been professionally building websites for the past 18 years. For the last 14 years, he has been working at a web design company, studio 38 pure communication, in Berlin. Together with a small dedicated team, he has mostly used Django in the backend and jQuery in the frontend to create cultural and touristic web platforms. Among different side projects, he is bootstrapping a SaaS business with strategic prioritizer 1st things 1st. Aidas Bendoraitis is active on Twitter and other social media under the username DjangoTricks.

Product details

Fair Use Source: B084WRLDSB


Detailed Table of Contents

  • Preface Who this book is for
  • What this book covers
  • To get the most out of this book Download the example code files
  • Conventions used
  • Sections
    • How to do it
    • How it works
    • There's more
    • See also
  • Get in touch
    • Reviews

Chapter 1 - Getting Started with Django

  • Including external dependencies in your project
  • Setting up STATIC_URL dynamically
  • Setting UTF-8 as the default encoding for the MySQL configuration
  • Creating the Git ignore file
  • Deleting Python-compiled files
  • Respecting the import order in Python files
  • Creating an app configuration
  • Defining overwritable app settings
  • Working with Docker containers for Django, Gunicorn, Nginx, and PostgreSQL

Chapter 2 Models and Database Structure

  • Models and Database Structure Introduction
  • Technical requirements
  • Using model mixins
  • Creating a model mixin with URL-related methods
  • Creating a model mixin to handle creation and modification dates
  • Creating a model mixin to take care of meta tags
  • Creating a model mixin to handle generic relations
  • Handling multilingual fields
  • Working with model translation tables
  • Avoiding circular dependencies
  • Adding database constraints
  • Using migrations
  • Changing a foreign key to the many-to-many field

Chapter 3 - Forms and Views

  • Forms and Views Introduction
  • Technical requirements
  • Creating an app with CRUDL functions
  • Saving the author of a model instance
  • Uploading images
  • Creating a form layout with custom templates
  • Creating a form layout with django-crispy-forms
  • Working with formsets
  • Filtering object lists
  • Managing paginated lists
  • Composing class-based views
  • Providing Open Graph and Twitter Card data
  • Providing schema.org vocabularies
  • Generating PDF documents
  • Implementing a multilingual search with Haystack and Whoosh
  • Implementing a multilingual search with Elasticsearch DSL

Chapter 4 - Templates and JavaScript

Templates and JavaScript Introduction

  • Technical requirements
  • Arranging the base.html template
  • Using Django Sekizai
  • Exposing settings in JavaScript
  • Using HTML5 data attributes
  • Providing responsive images
  • Implementing a continuous scrolling
  • Opening object details in a modal dialog
  • Implementing the Like widget
  • Uploading images via Ajax

Chapter 5 - Custom Template Filters and Tags

Custom Template Filters and Tags Introduction

  • Technical requirements
  • Following conventions for your own template filters and tags
  • Creating a template filter to show how many days have passed since a post was published
  • Creating a template filter to extract the first media object
  • Creating a template filter to humanize URLs
  • Creating a template tag to include a template, if it exists
  • Creating a template tag to load a QuerySet in a template
  • Creating a template tag to parse content as a template
  • Creating template tags to modify request query parameters

Chapter 6 - Model Administration

Model Administration Introduction

  • Technical requirements
  • Customizing columns on the change list page
  • Creating sortable inlines
  • Creating admin actions
  • Developing change list filters
  • Changing the app label of a third-party app
  • Creating a custom accounts app
  • Getting user Gravatars
  • Inserting a map into a change form

Chapter 7 - Security and Performance

Security and Performance Introduction

  • Technical requirements
  • Making forms secure from Cross-Site Request Forgery (CSRF)
  • Making requests secure with Content Security Policy (CSP)
  • Using django-admin-honeypot
  • Implementing password validation
  • Downloading authorized files
  • Adding a dynamic watermark to images
  • Authenticating with Auth0
  • Caching the method return value
  • Using Memcached to cache Django views
  • Using Redis to cache Django views

Chapter 8 - Hierarchical Structures

Hierarchical Structures=Introduction

  • Technical requirements
  • Creating hierarchical categories with django-mptt
  • Creating a category administration interface with django-mptt-admin
  • Rendering categories in a template with django-mptt
  • Using a single selection field to choose a category in forms with django-mptt
  • Using a checkbox list to choose multiple categories in forms with django-mptt
  • Creating hierarchical categories with django-treebeard
  • Creating a basic category administration interface with django-treebeard

Chapter 9 - Importing and Exporting Data

Importing and Exporting Data Introduction

  • Technical requirements
  • Importing data from a local CSV file
  • Importing data from a local Excel file
  • Importing data from an external JSON file
  • Importing data from an external XML file
  • Preparing paginated sitemaps for search engines
  • Creating filterable RSS feeds
  • Using Django REST framework to create an API

Chapter 10 - Bells and Whistles

Bells and Whistles Introduction

  • Technical requirements
  • Using the Django shell
  • Using database query expressions
  • Monkey patching the slugify() function for better internationalization support
  • Toggling the Debug toolbar
  • Using ThreadLocalMiddleware
  • Using signals to notify administrators about new entries
  • Checking for missing settings

Chapter 11 - Testing

Testing Introduction

  • Technical requirements
  • Testing views with mock
  • Testing the user interface with Selenium
  • Testing APIs created using Django REST framework
  • Ensuring test coverage

Chapter 12 - Deployment

Deployment Introduction

  • Technical requirements
  • Releasing a reusable Django app
  • Deploying on Apache with mod_wsgi for the staging environment
  • Deploying on Apache with mod_wsgi for the production environment
  • Deploying on Nginx and Gunicorn for the staging environment
  • Deploying on Nginx and Gunicorn for the production environment

Chapter 13 - Maintenance

Maintenance Introduction

  • Technical requirements
  • Creating and restoring MySQL database backups
  • Creating and restoring PostgreSQL database backups
  • Setting up cron jobs for regular tasks
  • Logging events for further introspection
  • Getting detailed error reporting via email
django_3_web_development_cookbook.txt · Last modified: 2024/04/28 03:17 (external edit)