𝔖 Scriptorium
✦   LIBER   ✦

πŸ“

Django 4 By Example - Fourth Edition: Build powerful and reliable Python web applications from scratch

✍ Scribed by Antonio Melé


Publisher
Packt Publishing
Year
2022
Tongue
English
Leaves
765
Edition
4
Category
Library

⬇  Acquire This Volume

No coin nor oath required. For personal study only.

✦ Synopsis


Learn to create fully functional web applications with authentication, content management systems, payment processing, RESTful APIs, and more

Purchase of the print or Kindle book includes a free eBook in PDF format.


Key Features:

    Implement advanced functionalities, such as full-text search engines, user activity streams, payment gateways, and recommendation engines Integrate JavaScript, PostgreSQL, Redis, Celery, and Memcached into your applications Add real-time features with Django Channels and WebSockets


    Book Description:

    Django 4 By Example is the 4th edition of the best-selling franchise that helps you build web apps. This book will walk you through the creation of real-world applications, solving common problems, and implementing best practices using a step-by-step approach. You'll cover a wide range of web app development topics as you build four different apps:

      A blog application: Create data models, views, and URLs and implement an admin site for your blog. Create sitemaps and RSS feeds and implement a full-text search engine with PostgreSQL. A social website: Implement authentication with Facebook, Twitter, and Google. Create user profiles, image thumbnails, a bookmarklet, and an activity stream. Implement a user follower system and add infinite scroll pagination to your website. An e-commerce application: Build a product catalog, a shopping cart, and asynchronous tasks with Celery and RabbitMQ. Process payments with Stripe and manage payment notifications via webhooks. Build a product recommendation engine with Redis. Create PDF invoices and export orders to CSV.

      • An e-learning platform: Create a content management system to manage polymorphic content. Cache content with Memcached and Redis. Build and consume a RESTful API. Implement a real-time chat using WebSockets with ASGI. Create a production environment using NGINX, uWSGI and Daphne with Docker Compose.

      This is a practical book that will have you creating web apps quickly.


      What You Will Learn:

      • Learn Django essentials, including models, ORM, views, templates, URLs, forms, authentication, signals and middleware
      • Implement different modules of the Django framework to solve specific problems
      • Integrate third-party Django applications into your project
      • Build asynchronous (ASGI) applications with Django
      • Set up a production environment for your projects
      • Easily create complex web applications to solve real use cases



      Who this book is for:

      This book is for readers with basic Python knowledge and programmers transitioning from other web frameworks who wish to learn Django by doing. If you already use Django or have in the past, and want to learn best practices and integrate other technologies to scale your applications, then this book is for you too. This book will help you master the most relevant areas of the framework by building practical projects from scratch. Some previous knowledge of HTML and JavaScript is assumed.

      ✦ Table of Contents


      Cover
      Copyright
      Foreword
      Contributors
      Table of Contents
      Preface
      Chapter 1: Building a Blog Application
      Installing Python
      Creating a Python virtual environment
      Installing Django
      Installing Django with pip
      New features in Django 4
      Django overview
      Main framework components
      The Django architecture
      Creating your first project
      Applying initial database migrations
      Running the development server
      Project settings
      Projects and applications
      Creating an application
      Creating the blog data models
      Creating the Post model
      Adding datetime fields
      Defining a default sort order
      Adding a database index
      Activating the application
      Adding a status field
      Adding a many-to-one relationship
      Creating and applying migrations
      Creating an administration site for models
      Creating a superuser
      The Django administration site
      Adding models to the administration site
      Customizing how models are displayed
      Working with QuerySets and managers
      Creating objects
      Updating objects
      Retrieving objects
      Using the filter() method
      Using exclude()
      Using order_by()
      Deleting objects
      When QuerySets are evaluated
      Creating model managers
      Building list and detail views
      Creating list and detail views
      Using the get_object_or_404 shortcut
      Adding URL patterns for your views
      Creating templates for your views
      Creating a base template
      Creating the post list template
      Accessing our application
      Creating the post detail template
      The request/response cycle
      Additional resources
      Summary
      Chapter 2: Enhancing Your Blog with Advanced Features
      Using canonical URLs for models
      Creating SEO-friendly URLs for posts
      Modifying the URL patterns
      Modifying the views
      Modifying the canonical URL for posts
      Adding pagination
      Adding pagination to the post list view
      Creating a pagination template
      Handling pagination errors
      Building class-based views
      Why use class-based views
      Using a class-based view to list posts
      Recommending posts by email
      Creating forms with Django
      Handling forms in views
      Sending emails with Django
      Sending emails in views
      Rendering forms in templates
      Creating a comment system
      Creating a model for comments
      Adding comments to the administration site
      Creating forms from models
      Handling ModelForms in views
      Creating templates for the comment form
      Adding comments to the post detail view
      Adding comments to the post detail template
      Additional resources
      Summary
      Chapter 3: Extending Your Blog Application
      Adding the tagging functionality
      Retrieving posts by similarity
      Creating custom template tags and filters
      Implementing custom template tags
      Creating a simple template tag
      Creating an inclusion template tag
      Creating a template tag that returns a QuerySet
      Implementing custom template filters
      Creating a template filter to support Markdown syntax
      Adding a sitemap to the site
      Creating feeds for blog posts
      Adding full-text search to the blog
      Installing PostgreSQL
      Creating a PostgreSQL database
      Dumping the existing data
      Switching the database in the project
      Loading the data into the new database
      Simple search lookups
      Searching against multiple fields
      Building a search view
      Stemming and ranking results
      Stemming and removing stop words in different languages
      Weighting queries
      Searching with trigram similarity
      Additional resources
      Summary
      Chapter 4: Building a Social Website
      Creating a social website project
      Starting the social website project
      Using the Django authentication framework
      Creating a login view
      Using Django authentication views
      Login and logout views
      Change password views
      Reset password views
      User registration and user profiles
      User registration
      Extending the user model
      Installing Pillow and serving media files
      Creating migrations for the profile model
      Using a custom user model
      Using the messages framework
      Building a custom authentication backend
      Preventing users from using an existing email
      Additional resources
      Summary
      Chapter 5: Implementing Social Authentication
      Adding social authentication to your site
      Running the development server through HTTPS
      Authentication using Facebook
      Authentication using Twitter
      Authentication using Google
      Creating a profile for users that register with social authentication
      Additional resources
      Summary
      Chapter 6: Sharing Content on Your Website
      Creating an image bookmarking website
      Building the image model
      Creating many-to-many relationships
      Registering the image model in the administration site
      Posting content from other websites
      Cleaning form fields
      Installing the Requests library
      Overriding the save() method of a ModelForm
      Building a bookmarklet with JavaScript
      Creating a detail view for images
      Creating image thumbnails using easy-thumbnails
      Adding asynchronous actions with JavaScript
      Loading JavaScript on the DOM
      Cross-site request forgery for HTTP requests in JavaScript
      Performing HTTP requests with JavaScript
      Adding infinite scroll pagination to the image list
      Additional resources
      Summary
      Chapter 7: Tracking User Actions
      Building a follow system
      Creating many-to-many relationships with an intermediary model
      Creating list and detail views for user profiles
      Adding user follow/unfollow actions with JavaScript
      Building a generic activity stream application
      Using the contenttypes framework
      Adding generic relations to your models
      Avoiding duplicate actions in the activity stream
      Adding user actions to the activity stream
      Displaying the activity stream
      Optimizing QuerySets that involve related objects
      Using select_related()
      Using prefetch_related()
      Creating templates for actions
      Using signals for denormalizing counts
      Working with signals
      Application configuration classes
      Using Django Debug Toolbar
      Installing Django Debug Toolbar
      Django Debug Toolbar panels
      Django Debug Toolbar commands
      Counting image views with Redis
      Installing Docker
      Installing Redis
      Using Redis with Python
      Storing image views in Redis
      Storing a ranking in Redis
      Next steps with Redis
      Additional resources
      Summary
      Chapter 8: Building an Online Shop
      Creating an online shop project
      Creating product catalog models
      Registering catalog models on the administration site
      Building catalog views
      Creating catalog templates
      Building a shopping cart
      Using Django sessions
      Session settings
      Session expiration
      Storing shopping carts in sessions
      Creating shopping cart views
      Adding items to the cart
      Building a template to display the cart
      Adding products to the cart
      Updating product quantities in the cart
      Creating a context processor for the current cart
      Context processors
      Setting the cart into the request context
      Registering customer orders
      Creating order models
      Including order models in the administration site
      Creating customer orders
      Asynchronous tasks
      Working with asynchronous tasks
      Workers, message queues, and message brokers
      Using Django with Celery and RabbitMQ
      Monitoring Celery with Flower
      Additional resources
      Summary
      Chapter 9: Managing Payments and Orders
      Integrating a payment gateway
      Creating a Stripe account
      Installing the Stripe Python library
      Adding Stripe to your project
      Building the payment process
      Integrating Stripe Checkout
      Testing the checkout process
      Using test credit cards
      Checking the payment information in the Stripe dashboard
      Using webhooks to receive payment notifications
      Creating a webhook endpoint
      Testing webhook notifications
      Referencing Stripe payments in orders
      Going live
      Exporting orders to CSV files
      Adding custom actions to the administration site
      Extending the administration site with custom views
      Generating PDF invoices dynamically
      Installing WeasyPrint
      Creating a PDF template
      Rendering PDF files
      Sending PDF files by email
      Additional resources
      Summary
      Chapter 10: Extending Your Shop
      Creating a coupon system
      Building the coupon model
      Applying a coupon to the shopping cart
      Applying coupons to orders
      Creating coupons for Stripe Checkout
      Adding coupons to orders on the administration site and to PDF invoices
      Building a recommendation engine
      Recommending products based on previous purchases
      Additional resources
      Summary
      Chapter 11: Adding Internationalization to Your Shop
      Internationalization with Django
      Internationalization and localization settings
      Internationalization management commands
      Installing the gettext toolkit
      How to add translations to a Django project
      How Django determines the current language
      Preparing your project for internationalization
      Translating Python code
      Standard translations
      Lazy translations
      Translations including variables
      Plural forms in translations
      Translating your own code
      Translating templates
      The {% trans %} template tag
      The {% blocktrans %} template tag
      Translating the shop templates
      Using the Rosetta translation interface
      Fuzzy translations
      URL patterns for internationalization
      Adding a language prefix to URL patterns
      Translating URL patterns
      Allowing users to switch language
      Translating models with django-parler
      Installing django-parler
      Translating model fields
      Integrating translations into the administration site
      Creating migrations for model translations
      Using translations with the ORM
      Adapting views for translations
      Format localization
      Using django-localflavor to validate form fields
      Additional resources
      Summary
      Chapter 12: Building an E-Learning Platform
      Setting up the e-learning project
      Serving media files
      Building the course models
      Registering the models in the administration site
      Using fixtures to provide initial data for models
      Creating models for polymorphic content
      Using model inheritance
      Abstract models
      Multi-table model inheritance
      Proxy models
      Creating the Content models
      Creating custom model fields
      Adding ordering to module and content objects
      Adding authentication views
      Adding an authentication system
      Creating the authentication templates
      Additional resources
      Summary
      Chapter 13: Creating a Content Management System
      Creating a CMS
      Creating class-based views
      Using mixins for class-based views
      Working with groups and permissions
      Restricting access to class-based views
      Managing course modules and their contents
      Using formsets for course modules
      Adding content to course modules
      Managing modules and their contents
      Reordering modules and their contents
      Using mixins from django-braces
      Additional resources
      Summary
      Chapter 14: Rendering and Caching Content
      Displaying courses
      Adding student registration
      Creating a student registration view
      Enrolling on courses
      Accessing the course contents
      Rendering different types of content
      Using the cache framework
      Available cache backends
      Installing Memcached
      Installing the Memcached Docker image
      Installing the Memcached Python binding
      Django cache settings
      Adding Memcached to your project
      Cache levels
      Using the low-level cache API
      Checking cache requests with Django Debug Toolbar
      Caching based on dynamic data
      Caching template fragments
      Caching views
      Using the per-site cache
      Using the Redis cache backend
      Monitoring Redis with Django Redisboard
      Additional resources
      Summary
      Chapter 15: Building an API
      Building a RESTful API
      Installing Django REST framework
      Defining serializers
      Understanding parsers and renderers
      Building list and detail views
      Consuming the API
      Creating nested serializers
      Building custom API views
      Handling authentication
      Adding permissions to views
      Creating ViewSets and routers
      Adding additional actions to ViewSets
      Creating custom permissions
      Serializing course contents
      Consuming the RESTful API
      Additional resources
      Summary
      Chapter 16: Building a Chat Server
      Creating a chat application
      Implementing the chat room view
      Real-time Django with Channels
      Asynchronous applications using ASGI
      The request/response cycle using Channels
      Installing Channels
      Writing a consumer
      Routing
      Implementing the WebSocket client
      Enabling a channel layer
      Channels and groups
      Setting up a channel layer with Redis
      Updating the consumer to broadcast messages
      Adding context to the messages
      Modifying the consumer to be fully asynchronous
      Integrating the chat application with existing views
      Additional resources
      Summary
      Chapter 17: Going Live
      Creating a production environment
      Managing settings for multiple environments
      Local environment settings
      Running the local environment
      Production environment settings
      Using Docker Compose
      Installing Docker Compose
      Creating a Dockerfile
      Adding the Python requirements
      Creating a Docker Compose file
      Configuring the PostgreSQL service
      Applying database migrations and creating a superuser
      Configuring the Redis service
      Serving Django through WSGI and NGINX
      Using uWSGI
      Configuring uWSGI
      Using NGINX
      Configuring NGINX
      Using a hostname
      Serving static and media assets
      Collecting static files
      Serving static files with NGINX
      Securing your site with SSL/TLS
      Checking your project for production
      Configuring your Django project for SSL/TLS
      Creating an SSL/TLS certificate
      Configuring NGINX to use SSL/TLS
      Redirecting HTTP traffic over to HTTPS
      Using Daphne for Django Channels
      Using secure connections for WebSockets
      Including Daphne in the NGINX configuration
      Creating a custom middleware
      Creating a subdomain middleware
      Serving multiple subdomains with NGINX
      Implementing custom management commands
      Additional resources
      Summary
      Other Books You May Enjoy
      Index


      πŸ“œ SIMILAR VOLUMES


      Django 4 By Example: Build powerful and
      ✍ Antonio Mele πŸ“‚ Library πŸ“… 2022 πŸ› Packt Publishing 🌐 English

      <p><span>Learn to create fully functional web applications with authentication, content management systems, payment processing, RESTful APIs, and more</span></p><h4><span>Key Features</span></h4><ul><li><span><span>Implement advanced functionalities, such as full-text search engines, user activity s

      Django 4 By Example: Build powerful and
      ✍ Antonio Mele πŸ“‚ Library πŸ“… 2022 πŸ› Packt Publishing 🌐 English

      <p><span>Learn to create fully functional web applications with authentication, content management systems, payment processing, RESTful APIs, and more</span></p><h4><span>Key Features</span></h4><ul><li><span><span>Implement advanced functionalities, such as full-text search engines, user activity s

      Django 3 By Example Build powerful and r
      ✍ Antonio MelΓ© πŸ“‚ Library πŸ“… 2020 πŸ› Packt 🌐 English

      Learn Django 3 with four end-to-end web projects Key Features Learn Django 3 by building real-world web applications from scratch in Python, using coding best practices Integrate other technologies into your application with clear, step-by-step explanations and comprehensive example code Imple

      Django 3 By Example: Build powerful and
      ✍ Antonio MelΓ© πŸ“‚ Library πŸ“… 2020 πŸ› Packt Publishing Ltd 🌐 English

      Learn Django 3 with four end-to-end web projects Key Features Learn Django 3 by building real-world web applications from scratch in Python, using coding best practices Integrate other technologies into your application with clear, step-by-step explanations and comprehensive example code Implement a

      Django 5 By Example: Build powerful and
      ✍ Antonio MelΓ© πŸ“‚ Library πŸ“… 2024 πŸ› Packt Publishing 🌐 English

      If you want to learn Django by doing, this book is for you. Django 5 By Example is the fifth edition of the best-selling franchise that helps you build real-world web apps. This book will walk you through planning and creation, solving common problems, and implementing best practices using a step-b

      Django 5 By Example: Build powerful and
      ✍ Antonio MelΓ© πŸ“‚ Library πŸ“… 2024 πŸ› Packt Publishing 🌐 English

      If you want to learn Django by doing, this book is for you. Django 5 By Example is the fifth edition of the best-selling franchise that helps you build real-world web apps. This book will walk you through planning and creation, solving common problems, and implementing best practices using a step-b