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
- Title Page
- Copyright and Credits
- Dedication
- Packt.com
- Contributors
- Preface
-
Getting Started with Django 2.1
- Introduction
- Working with a virtual environment
- Creating a virtual environment project file structure
- Working with Docker
- Creating a Docker project file structure
- Handling project dependencies with pip
- Including external dependencies in your project
- Configuring settings for development, testing, staging, and production environments
- Defining relative paths in the settings
- Creating and including local settings
- Setting up STATIC_URL dynamically for Subversion users
- Setting up STATIC_URL dynamically for Git users
- Setting UTF-8 as the default encoding for MySQL configuration
- Setting the Subversion ignore property
- Creating the Git ignore file
- Deleting Python-compiled files
- Respecting the import order in Python files
- Creating app configuration
- Defining overwritable app settings
-
Database Structure and Modeling
- Introduction
- 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
- Enabling schema microdata enhancements
- Using migrations
- Switching from South migrations to Django migrations
- Changing a foreign key to the many-to-many field
-
Forms and Views
- Introduction
- Passing HttpRequest to a form
- Utilizing the save method of the form
- Uploading images
- Creating a form layout with custom templates
- Creating a form layout with django-crispy-forms
- Filtering object lists
- Managing paginated lists
- Composing class-based views
- Generating PDF documents
- Implementing a multilingual search with Haystack and Whoosh
- Templates and JavaScript
-
Customizing Template Filters and Tags
- Introduction
- Following conventions for your own template filters and tags
- Creating a template filter to show how much time has 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 a template tag to modify request query parameters
- Model Administration
-
Security and Performance
- Introduction
- Making forms secure from Cross Site Request Forgery (CSRF)
- 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
- Django CMS
-
Hierarchical Structures
- Introduction
- 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
- Importing and Exporting Data
- Bells and Whistles
- Testing and Deployment
- Other Books You May Enjoy
Product information
- Title: Django 2 Web Development Cookbook - Third Edition
- Author(s):
- Release date: October 2018
- Publisher(s): Packt Publishing
- ISBN: 9781788837682
You might also like
book
Beginning Django: Web Application Development and Deployment with Python
Discover the Django web application framework and get started building Python-based web applications. This book takes …
book
Django Standalone Apps: Learn to Develop Reusable Django Libraries
Develop standalone Django apps to serve as the reusable building blocks for larger Django projects. This …
book
Django: Web Development with Python
From an idea to a prototype – a complete guide for web development with the Django …
book
Django 2 by Example
Learn Django 2.0 with four end-to-end projects About This Book Learn Django by building real-world web …