Django 3 By Example - Antonio Mele - E-Book

Django 3 By Example E-Book

Antonio Mele

0,0
46,44 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 647

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Django 3 By Example

Third Edition

Build powerful and reliable Python web applications from scratch

Antonio Melé

BIRMINGHAM - MUMBAI

Django 3 By Example

Third Edition

Copyright © 2020 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Commissioning Editor: Pavan Ramchandani

Producer: Ben Renow-Clarke

Acquisition Editor – Peer Reviews: Suresh Jain

Content Development Editor: Joanne Lovell

Technical Editor: Saby D'silva

Project Editor: Kishor Rit

Proofreader: Safis Editing

Indexer: Pratik Shirodkar

Presentation Designer: Pranit Padwal

First published: November 2015

Second edition: May 2018

Third edition: March 2020

Production reference: 1310320

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-83898-195-2

www.packt.com

This book is dedicated to my parents, Antonio and Lola, who have always supported me in all my ventures.

packt.com

Subscribe to our online digital library for full access to over 7,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and videos from over 4,000 industry professionalsLearn better with Skill Plans built especially for youGet a free eBook or video every monthFully searchable for easy access to vital informationCopy and paste, print, and bookmark content

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.Packt.com and, as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.Packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

Contributors

About the author

Antonio Melé is the chief technology officer (CTO) at Nucoro, a London-based fintech company that provides a leading technology platform to build digital wealth management solutions. Antonio has been developing Django projects since 2006 for clients across several industries. In 2009, he founded Zenx IT, a development company specializing in building digital products. He has worked as a CTO and technology consultant for multiple technology-based start-ups and he has managed development teams building projects for large digital businesses. Antonio holds an M.Sc. in computer science from Universidad Pontificia Comillas. His father inspired his passion for computers and programming. You can find out more about Antonio on his website https://antoniomele.es/.

About the reviewers

Jake Kronika, a senior software engineer with nearly 25 years' experience, has been working with Python since 2005, and Django since 2007. Evolving alongside the web development space, his skill set encompasses HTML5, CSS3, and JavaScript (ECMAScript 6) on the frontend, plus Python, Django, Node.js, PHP, Ruby on Rails, and much more besides on the server side.

Currently a software architect and development team lead, Jake collaborates with skilled designers, business stakeholders, and developers around the world to plan and implement robust web applications. In his spare time, he also provides full-spectrum web services as sole proprietor of Gridline Design and Development, works on home improvement projects, and spends valued time with his wife and two children.

Jake coauthored Django 2 Web Development Cookbook, Third Edition, published in October 2018, and Django 3 Web Development Cookbook, Fourth Edition, published in March 2020. In addition, he has acted as a technical reviewer for several other Packt titles, including:

Web Development with Django Cookbook – Second Edition (2016)Developing Responsive Web Applications with AJAX and jQuery (2014)jQuery Tools UI Library (2012)jQuery UI 1.8: The User Interface Library for jQuery (2011)Django JavaScript Integration: AJAX and jQuery (2011)

"I would like to thank my wife, Veronica, for all that she does to support me. Without her, I would be a fraction of the person I am, and would have accomplished only a small percentage of what I've been able to.

Also, I would like to acknowledge my manager, Ravi, for his ongoing support and advice. His guidance has been critical at several points of advancement in my career."

David Stanek has been developing software professionally for over 22 years. He currently enjoys building distributed systems with Kubernetes and cloud technologies. Python has been his language of choice for over 19 years, but he also enjoys writing in Go and other specialized languages. In recent years, he has been involved with various cloud-related projects and enjoys the challenges of running applications at scale. For him, there's nothing better than writing a web service in Python, deploying it on infrastructure orchestrated with Terraform, and automating its business processes with Ansible.

David spends much of his free work time working on open source projects and sharpening his technical skills. He enjoys teaching, reading technical books, and listening to a variety of podcasts and audio books. When he's not working, he enjoys spending time with his beautiful wife, four wonderful children, and miniature dachshund.

You can find out more about David on his website (http://dstanek.com/).

Contents

Preface

Who this book is for

What this book covers

Get the most out of this book

Download the example code files

Download the color images

Conventions used

Get in touch

Reviews

Building a Blog Application

Installing Django

Creating an isolated Python environment

Installing Django with pip

Creating your first project

Running the development server

Project settings

Projects and applications

Creating an application

Designing the blog data schema

Activating the application

Creating and applying migrations

Creating an administration site for models

Creating a superuser

The Django administration site

Adding models to the administration site

Customizing the way that 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

Adding URL patterns for your views

Canonical URLs for models

Creating templates for your views

Adding pagination

Using class-based views

Summary

Enhancing Your Blog with Advanced Features

Sharing posts by email

Creating forms with Django

Handling forms in views

Sending emails with Django

Rendering forms in templates

Creating a comment system

Building a model

Creating forms from models

Handling ModelForms in views

Adding comments to the post detail template

Adding the tagging functionality

Retrieving posts by similarity

Summary

Extending Your Blog Application

Creating custom template tags and filters

Custom template tags

Custom template filters

Adding a sitemap to your site

Creating feeds for your blog posts

Adding full-text search to your blog

Installing PostgreSQL

Simple search lookups

Searching against multiple fields

Building a search view

Stemming and ranking results

Weighting queries

Searching with trigram similarity

Other full-text search engines

Summary

Building a Social Website

Creating a social website project

Starting your social website project

Using the Django authentication framework

Creating a login view

Using Django authentication views

Login and logout views

Changing password views

Resetting password views

User registration and user profiles

User registration

Extending the user model

Using a custom user model

Using the messages framework

Building a custom authentication backend

Adding social authentication to your site

Running the development server through HTTPS

Authentication using Facebook

Authentication using Twitter

Authentication using Google

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

Overriding the save() method of a ModelForm

Building a bookmarklet with jQuery

Creating a detail view for images

Creating image thumbnails using easy-thumbnails

Adding AJAX actions with jQuery

Loading jQuery

Cross-site request forgery in AJAX requests

Performing AJAX requests with jQuery

Creating custom decorators for your views

Adding AJAX pagination to your list views

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

Building an AJAX view to follow users

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 Redis for storing item views

Installing Redis

Using Redis with Python

Storing item views in Redis

Storing a ranking in Redis

Next steps with Redis

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

Launching asynchronous tasks with Celery

Installing Celery

Installing RabbitMQ

Adding Celery to your project

Adding asynchronous tasks to your application

Monitoring Celery

Summary

Managing Payments and Orders

Integrating a payment gateway

Creating a Braintree sandbox account

Installing the Braintree Python module

Integrating the payment gateway

Integrating Braintree using Hosted Fields

Testing payments

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

Summary

Extending Your Shop

Creating a coupon system

Building the coupon model

Applying a coupon to the shopping cart

Applying coupons to orders

Adding internationalization and localization

Internationalization with Django

Internationalization and localization settings

Internationalization management commands

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

Adapting views for translations

Format localization

Using django-localflavor to validate form fields

Building a recommendation engine

Recommending products based on previous purchases

Summary

Building an E-Learning Platform

Setting up the e-learning project

Building the course models

Registering the models in the administration site

Using fixtures to provide initial data for models

Creating models for diverse 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

Creating a CMS

Adding an authentication system

Creating the authentication templates

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

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

Cache settings

Adding Memcached to your project

Monitoring Memcached

Cache levels

Using the low-level cache API

Caching based on dynamic data

Caching template fragments

Caching views

Using the per-site cache

Summary

Building an API

Building a RESTful API

Installing Django REST framework

Defining serializers

Understanding parsers and renderers

Building list and detail views

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 

Summary

Building a Chat Server

Creating a chat application

Implementing the chat room view

Deactivating the per-site cache

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

Summary

Going Live

Creating a production environment

Managing settings for multiple environments

Using PostgreSQL

Checking your project

Serving Django through WSGI

Installing uWSGI

Configuring uWSGI

Installing NGINX

The production environment

Configuring NGINX

Serving static and media assets

Securing connections with SSL/TLS

Creating an SSL/TLS certificate

Configuring NGINX to use SSL/TLS

Configuring your Django project for 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

Summary

Other Books You May Enjoy

Index

Landmarks

Cover

Index