0%

Book Description

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 advanced functionalities like a full-text search engine, a user activity stream, or a recommendation engine
  • Add real-time features with Django Channels and WebSockets

Book Description

If you want to learn the entire process of developing professional web applications with Python and Django, then this book is for you. In the process of building four professional Django projects, you will learn about Django 3 features, how to solve common web development problems, how to implement best practices, and how to successfully deploy your applications.

In this book, you will build a blog application, a social image bookmarking website, an online shop, and an e-learning platform. Step-by-step guidance will teach you how to integrate popular technologies, enhance your applications with AJAX, create RESTful APIs, and set up a production environment for your Django projects.

By the end of this book, you will have mastered Django 3 by building advanced web applications.

What you will learn

  • Build real-world web applications
  • Learn Django essentials, including models, views, ORM, templates, URLs, forms, and authentication
  • Implement advanced features such as custom model fields, custom template tags, cache, middleware, localization, and more
  • Create complex functionalities, such as AJAX interactions, social authentication, a full-text search engine, a payment system, a CMS, a RESTful API, and more
  • Integrate other technologies, including Redis, Celery, RabbitMQ, PostgreSQL, and Channels, into your projects
  • Deploy Django projects in production using NGINX, uWSGI, and Daphne

Who this book is for

This book is intended for developers with Python knowledge who wish to learn Django in a pragmatic way. Perhaps you are completely new to Django, or you already know a little but you want to get the most out of it. This book will help you to master the most relevant areas of the framework by building practical projects from scratch. You need to have familiarity with programming concepts in order to read this book. Some previous knowledge of HTML and JavaScript is assumed.

Table of Contents

  1. Preface
    1. Who this book is for
    2. What this book covers
    3. Get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  2. Building a Blog Application
    1. Installing Django
      1. Creating an isolated Python environment
      2. Installing Django with pip
    2. Creating your first project
      1. Running the development server
      2. Project settings
      3. Projects and applications
      4. Creating an application
    3. Designing the blog data schema
      1. Activating the application
      2. Creating and applying migrations
    4. Creating an administration site for models
      1. Creating a superuser
      2. The Django administration site
      3. Adding models to the administration site
      4. Customizing the way that models are displayed
    5. Working with QuerySets and managers
      1. Creating objects
      2. Updating objects
      3. Retrieving objects
        1. Using the filter() method
        2. Using exclude()
        3. Using order_by()
      4. Deleting objects
      5. When QuerySets are evaluated
      6. Creating model managers
    6. Building list and detail views
      1. Creating list and detail views
      2. Adding URL patterns for your views
      3. Canonical URLs for models
    7. Creating templates for your views
    8. Adding pagination
    9. Using class-based views
    10. Summary
  3. Enhancing Your Blog with Advanced Features
    1. Sharing posts by email
      1. Creating forms with Django
      2. Handling forms in views
      3. Sending emails with Django
      4. Rendering forms in templates
    2. Creating a comment system
      1. Building a model
      2. Creating forms from models
      3. Handling ModelForms in views
      4. Adding comments to the post detail template
    3. Adding the tagging functionality
    4. Retrieving posts by similarity
    5. Summary
  4. Extending Your Blog Application
    1. Creating custom template tags and filters
      1. Custom template tags
      2. Custom template filters
    2. Adding a sitemap to your site
    3. Creating feeds for your blog posts
    4. Adding full-text search to your blog
      1. Installing PostgreSQL
      2. Simple search lookups
      3. Searching against multiple fields
      4. Building a search view
      5. Stemming and ranking results
      6. Weighting queries
      7. Searching with trigram similarity
      8. Other full-text search engines
    5. Summary
  5. Building a Social Website
    1. Creating a social website project
      1. Starting your social website project
    2. Using the Django authentication framework
      1. Creating a login view
      2. Using Django authentication views
      3. Login and logout views
      4. Changing password views
      5. Resetting password views
    3. User registration and user profiles
      1. User registration
      2. Extending the user model
        1. Using a custom user model
      3. Using the messages framework
    4. Building a custom authentication backend
    5. Adding social authentication to your site
      1. Running the development server through HTTPS
      2. Authentication using Facebook
      3. Authentication using Twitter
      4. Authentication using Google
    6. Summary
  6. Sharing Content on Your Website
    1. Creating an image bookmarking website
      1. Building the image model
      2. Creating many-to-many relationships
      3. Registering the image model in the administration site
    2. Posting content from other websites
      1. Cleaning form fields
      2. Overriding the save() method of a ModelForm
      3. Building a bookmarklet with jQuery
    3. Creating a detail view for images
    4. Creating image thumbnails using easy-thumbnails
    5. Adding AJAX actions with jQuery
      1. Loading jQuery
      2. Cross-site request forgery in AJAX requests
      3. Performing AJAX requests with jQuery
    6. Creating custom decorators for your views
    7. Adding AJAX pagination to your list views
    8. Summary
  7. Tracking User Actions
    1. Building a follow system
      1. Creating many-to-many relationships with an intermediary model
      2. Creating list and detail views for user profiles
      3. Building an AJAX view to follow users
    2. Building a generic activity stream application
      1. Using the contenttypes framework
      2. Adding generic relations to your models
      3. Avoiding duplicate actions in the activity stream
      4. Adding user actions to the activity stream
      5. Displaying the activity stream
      6. Optimizing QuerySets that involve related objects
        1. Using select_related()
        2. Using prefetch_related()
      7. Creating templates for actions
    3. Using signals for denormalizing counts
      1. Working with signals
      2. Application configuration classes
    4. Using Redis for storing item views
      1. Installing Redis
      2. Using Redis with Python
      3. Storing item views in Redis
      4. Storing a ranking in Redis
      5. Next steps with Redis
    5. Summary
  8. Building an Online Shop
    1. Creating an online shop project
      1. Creating product catalog models
      2. Registering catalog models on the administration site
      3. Building catalog views
      4. Creating catalog templates
    2. Building a shopping cart
      1. Using Django sessions
      2. Session settings
      3. Session expiration
      4. Storing shopping carts in sessions
      5. Creating shopping cart views
        1. Adding items to the cart
        2. Building a template to display the cart
        3. Adding products to the cart
        4. Updating product quantities in the cart
      6. Creating a context processor for the current cart
        1. Context processors
        2. Setting the cart into the request context
    3. Registering customer orders
      1. Creating order models
      2. Including order models in the administration site
      3. Creating customer orders
    4. Launching asynchronous tasks with Celery
      1. Installing Celery
      2. Installing RabbitMQ
      3. Adding Celery to your project
      4. Adding asynchronous tasks to your application
      5. Monitoring Celery
    5. Summary
  9. Managing Payments and Orders
    1. Integrating a payment gateway
      1. Creating a Braintree sandbox account
      2. Installing the Braintree Python module
      3. Integrating the payment gateway
        1. Integrating Braintree using Hosted Fields
      4. Testing payments
      5. Going live
    2. Exporting orders to CSV files
      1. Adding custom actions to the administration site
    3. Extending the administration site with custom views
    4. Generating PDF invoices dynamically
      1. Installing WeasyPrint
      2. Creating a PDF template
      3. Rendering PDF files
      4. Sending PDF files by email
    5. Summary
  10. Extending Your Shop
    1. Creating a coupon system
      1. Building the coupon model
      2. Applying a coupon to the shopping cart
      3. Applying coupons to orders
    2. Adding internationalization and localization
      1. Internationalization with Django
        1. Internationalization and localization settings
        2. Internationalization management commands
        3. How to add translations to a Django project
        4. How Django determines the current language
      2. Preparing your project for internationalization
      3. Translating Python code
        1. Standard translations
        2. Lazy translations
        3. Translations including variables
        4. Plural forms in translations
        5. Translating your own code
      4. Translating templates
        1. The {% trans %} template tag
        2. The {% blocktrans %} template tag
        3. Translating the shop templates
      5. Using the Rosetta translation interface
      6. Fuzzy translations
      7. URL patterns for internationalization
        1. Adding a language prefix to URL patterns
        2. Translating URL patterns
      8. Allowing users to switch language
      9. Translating models with django-parler
        1. Installing django-parler
        2. Translating model fields
        3. Integrating translations into the administration site
        4. Creating migrations for model translations
        5. Adapting views for translations
      10. Format localization
      11. Using django-localflavor to validate form fields
    3. Building a recommendation engine
      1. Recommending products based on previous purchases
    4. Summary
  11. Building an E-Learning Platform
    1. Setting up the e-learning project
    2. Building the course models
      1. Registering the models in the administration site
      2. Using fixtures to provide initial data for models
    3. Creating models for diverse content
      1. Using model inheritance
        1. Abstract models
        2. Multi-table model inheritance
        3. Proxy models
      2. Creating the content models
      3. Creating custom model fields
      4. Adding ordering to module and content objects
    4. Creating a CMS
      1. Adding an authentication system
      2. Creating the authentication templates
      3. Creating class-based views
      4. Using mixins for class-based views
      5. Working with groups and permissions
        1. Restricting access to class-based views
    5. Managing course modules and their contents
      1. Using formsets for course modules
      2. Adding content to course modules
      3. Managing modules and their contents
      4. Reordering modules and their contents
        1. Using mixins from django-braces
    6. Summary
  12. Rendering and Caching Content
    1. Displaying courses
    2. Adding student registration
      1. Creating a student registration view
      2. Enrolling on courses
    3. Accessing the course contents
      1. Rendering different types of content
    4. Using the cache framework
      1. Available cache backends
      2. Installing Memcached
      3. Cache settings
      4. Adding Memcached to your project
        1. Monitoring Memcached
      5. Cache levels
      6. Using the low-level cache API
        1. Caching based on dynamic data
      7. Caching template fragments
      8. Caching views
        1. Using the per-site cache
    5. Summary
  13. Building an API
    1. Building a RESTful API
      1. Installing Django REST framework
      2. Defining serializers
      3. Understanding parsers and renderers
      4. Building list and detail views
      5. Creating nested serializers
      6. Building custom API views
      7. Handling authentication
      8. Adding permissions to views
      9. Creating viewsets and routers
      10. Adding additional actions to viewsets
      11. Creating custom permissions
      12. Serializing course contents
      13. Consuming the RESTful API 
    2. Summary
  14. Building a Chat Server
    1. Creating a chat application
      1. Implementing the chat room view
      2. Deactivating the per-site cache
    2. Real-time Django with Channels
      1. Asynchronous applications using ASGI
      2. The request/response cycle using Channels
    3. Installing Channels
    4. Writing a consumer
    5. Routing
    6. Implementing the WebSocket client
    7. Enabling a channel layer
      1. Channels and groups
      2. Setting up a channel layer with Redis
      3. Updating the consumer to broadcast messages
      4. Adding context to the messages
    8. Modifying the consumer to be fully asynchronous
    9. Integrating the chat application with existing views
    10. Summary
  15. Going Live
    1. Creating a production environment
      1. Managing settings for multiple environments
      2. Using PostgreSQL
      3. Checking your project
      4. Serving Django through WSGI
      5. Installing uWSGI
      6. Configuring uWSGI
      7. Installing NGINX
      8. The production environment
      9. Configuring NGINX
      10. Serving static and media assets
      11. Securing connections with SSL/TLS
        1. Creating an SSL/TLS certificate
        2. Configuring NGINX to use SSL/TLS
        3. Configuring your Django project for SSL/TLS
        4. Redirecting HTTP traffic over to HTTPS
      12. Using Daphne for Django Channels
      13. Using secure connections for WebSockets
      14. Including Daphne in the NGINX configuration
      15. Creating a custom middleware
        1. Creating a subdomain middleware
        2. Serving multiple subdomains with NGINX
    2. Implementing custom management commands
    3. Summary
  16. Other Books You May Enjoy
  17. Index
18.116.51.117