Home Page Icon
Home Page
Table of Contents for
Django 4 By Example - Fourth Edition
Close
Django 4 By Example - Fourth Edition
by Antonio Melé, Bob Belderbos
Django 4 By Example - Fourth Edition
Preface
Building a Blog Application
Enhancing Your Blog with Advanced Features
Extending Your Blog Application
Building a Social Website
Implementing Social Authentication
Sharing Content on Your Website
Tracking User Actions
Building an Online Shop
Managing Payments and Orders
Extending Your Shop
Adding Internationalization to Your Shop
Building an E-Learning Platform
Creating a Content Management System
Rendering and Caching Content
Building an API
Building a Chat Server
Going Live
Other Books You May Enjoy
Index
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Django 4 By Example - Fourth Edition
Next
Next Chapter
Preface
Contents
Preface
Who this book is for
What this book covers
To get the most out of this book
Get in touch
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
Join us on Discord.
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
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
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
Join us on Discord.
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
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
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
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
Join us on Discord.
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
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
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
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
Join us on Discord.
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
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
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
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
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
Landmarks
Cover
Index
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset