Ultimate Django for Web App Development Using Python: Build Modern, Reliable and Scalable Production-Grade Web Applications with Django and Python

Ultimate Django for Web App Development Using Python: Build Modern, Reliable and Scalable Production-Grade Web Applications with Django and Python

Ultimate Django for Web App Development Using Python: Build Modern, Reliable and Scalable Production-Grade Web Applications with Django and Python
Автор: Lazzaro Leonardo Luis
Дата выхода: 2024
Издательство: Orange Education Pvt Ltd, AVA™
Количество страниц: 396
Размер файла: 2,1 МБ
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы

Cover Page

Title Page

Copyright Page

About the Author

About the Technical Reviewer

Acknowledgements

Preface

Errata

Table of Contents

1. Introduction to Django and Python

Introduction

Structure

Introduction to Python

Understanding variables as references

Parameter passing

Interfaces or protocols

Standard modules

Error handling

List comprehensions

F-Strings

Type hinting

Coding style

Introduction to Django

The Django Philosophy

Don’t repeat yourself

Loose coupling and High cohesion

Less code and quick development

Explicit is better than implicit

Models: Include all relevant domain logic

Separate logic from the presentation on templates

Views

Caching

Django 4.2 highlights

Support for psycopg3

Comments on columns and tables

In-memory file storage

Custom file storages

Updates in password validation

Minor updates and additions

Python for Django

Conclusion

Questions

2. Setting Up Your Development Environment

Introduction

Structure

Introduction to Development Environments

Managing Python Versions with Pyenv

Understanding Virtual Environments

Introduction to Poetry for Dependency Management

Setting up a Django Project with Poetry

Basic Configuration for a Django Project

Introduction to Git for Version Control

Creating a GitHub repository

Branching models

Git Flow

GitHub Flow

Trunk-based

Advanced Git Usage: Using Worktree

Conclusion

Questions

3. Getting Started with Django Projects and Apps

Introduction

Structure

Introduction to the task manager

Django project versus Django application

Creating a new Django project

Understanding the Django project structure

Starting your first Django app

Understanding the Django app structure

MVT design patterns in Django

Extending the MVT pattern with a service layer

Configuring your Django app

Brief introduction to Django’s development server

Running your first Django app

Conclusion

Questions

Exercises

4. Django Models and PostgreSQL

Introduction

Structure

Understanding Django models

Creating your first model

Django’s database API: Create, retrieve, update, and delete operations

Understanding Django migrations

Django’s admin interface: Registering models and manipulating data

Introduction to Django’s ORM: Queries and aggregations

Extending the models

Ensuring data integrity with model constraints

Conclusion

Questions

Exercises

5. Django Views and URL Handling

Introduction

Structure

Understanding Django Views

Introducing Django’s Generic Views

Writing Your First Django View

Class-based Views Mixins

URL Configuration in Django

Creating URL Patterns for your Views

Handling Dynamic URLs with Path Converters

Understanding Django’s URL Namespace and Naming URL Patterns

Using Django’s HttpRequest And HttpResponse Objects

Introducing to Function-based Views

Using Function-based Views with a Service Layer

Pessimistic and Optimistic Offline Locking using Views and a Service Layer

Error Handling with Custom Error Views

Conclusion

Questions

Exercises

6. Using the Django Template Engine

Introduction

Structure

Introduction to Django Template Engine

Django Template Language: Variables, Tags, and Filters

Inheritance in Django Templates

The Home Page View: Showing Tasks by Status

Custom Template Tags and Filters

Using Static Files in Django Templates: CSS, JavaScript, Images

Django Template Context Processors

Debugging Django Templates

Optimizing Template Rendering

Securing Django Templates

Conclusion

Questions

Exercises

7. Forms in Django

Introduction

Structure

Understanding Django Forms

Creating Your First Django Form

Rendering Forms in Templates

Handling Form Submission in Views

Working with Form Fields

Custom form fields

File and Image Upload Field

Data Validation with Django Forms

Validators

Clean methods

ModelForm Validation

Displaying Form Errors

Advanced Form Handling: ModelFormsSets and Formsets

Preventing Double Submission in Forms

Conclusion

Questions

Exercises

8. User Authentication and Authorization in Django

Introduction

Structure

Understanding Django’s Authentication System

Introduction to Django’s Middleware

Understanding Django Middleware

User Registration with Django’s User Model

Authenticating Users: Login and Logout

Managing User Sessions

Session customization

Session usage

Session good practices

Password Management in Django: Change and Password Reset

Protecting Views with Login Required Decorators

User Authorization: Permissions and Groups

Multi-tenant authentication with Custom Django’s User Model

Security Best Practices in Django

Update all your libraries and frameworks

Project Settings Hardening

Turn off Debug in production

Use Secure Cookies

HTTP Strict Transport Security (HSTS)

Content Security Policy (CSP)

X-Content-Type-Options

X-XSS-Protection

Secure Referrer Policy

Use Secure Password Hashing Algorithms

Limit Access to Admin

Keep SECRET_KEY Secret

Set ALLOWED_HOSTS

Conclusion

Questions

Exercises

9. Django Ninja and APIs

Introduction

Structure

Introduction to API design

API Design-first approach

HTTP Response status codes

Introduction to Django Ninja

Setting Up Django Ninja in Your Project

Building Your first API with Django Ninja

Request and Response Models with Pydantic

API Documentation

Understanding HTTP Methods in Django Ninja

API Pagination

Working with Path Parameters and Query Parameters

Validation and Error Handling in Django Ninja

Authenticating API Users

Securing APIs: Permissions and Throttling

Permissions

Throttling

Versioning Your API

Conclusion

Questions

Exercises

10. Testing with pytest

Introduction

Structure

Introduction to testing and pytest

Understanding test

Test-driven development

Introduction to pytest

Installing and setting up pytest for Django

Understanding Django test database and pytest

Pytest-django fixtures

Mocking and patching in tests

Behavior-driven development

Advanced pytest features: Parametrization, plugins, and configuration

Parametrization

Plugin coverage

Plugin xdist

Using marks

Configuration tips

Conclusion

Questions

Exercises

11. Deploying Django Applications with Gunicorn and Docker

Introduction

Structure

Introduction to Gunicorn

Configuring Gunicorn for Django Deployment

Understanding and Creating Dockerfiles for Django

Using the image registry

Introduction to Kubernetes

Cluster

Node

Scheduler

Pods

Deployments

ReplicaSets

Services

Configmaps and Secrets

Ingress

StatefulSets

Configuring a Kubernetes cluster for a Django application

Adding liveness and readiness probes

Adding Instrumentation for Django

Prometheus configuration

Jaeger configuration

Database Optimization: Queries and Indexing

Conclusion

Questions

12. Final Thoughts and Future Directions

Introduction

Structure

Summary of learnings: Building a task management app

Evaluating the Django ecosystem: Strengths and weaknesses

Exploring additional Django tools and libraries

Potential enhancements for the task management app

Staying updated with Django: Resources and communities

Career opportunities with Django skills

Thoughts on Django’s future: Upcoming features and trends

Tips for continued learning and improvement

Conclusion

Index

This comprehensive guide is an indispensable resource for developers seeking to elevate their web development skills in Django and Python. The book begins by establishing a strong foundation and understanding of Django's architecture, emphasizing the Model-View-Template (MVT) pattern and a pivotal service layer for creating scalable web applications. The book then progresses to practical aspects, guiding readers through the development of a Task Management App. This hands-on approach reinforces fundamental concepts and showcases Django's flexibility and efficiency in real-world scenarios.

The advanced sections of the book will help you tackle complex challenges, covering topics like preventing double-form submissions, implementing offline pessimistic and optimistic locking techniques, mastering API development with Django Ninja, and ensuring application reliability through exhaustive testing with pytest. The book culminates in practical insights for deploying Django applications with Docker and Kubernetes, this guide equips you to tackle real-world challenges effectively.

What you will learn

  • Unlock the potential of Django 4.2 and Python for robust web development expertise.
  • Seamlessly build and deploy a complete Django project, implementing essential features like authentication, authorization, and multi-tenant capabilities.
  • Develop and secure APIs with Django Ninja, following best practices for a streamlined process.
  • Gain mastery in testing with pytest, ensuring the creation of reliable, bug-free Django applications.
  • Elevate your skills and create web solutions with confidence using the latest tools and techniques in Django development.

Who is this book for?

This book caters to web development enthusiasts, Python developers and experienced programmers looking to build scalable web apps with Django. Whether you're new to programming or seeking advanced insights, this guide offers a progressive approach. Beginners establish a strong foundation, while seasoned developers delve into advanced topics like preventing double-form submissions and implementing locking techniques.


Похожее:

Список отзывов:

Нет отзывов к книге.