Django in Action

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Build professional quality web applications using Python and the Django 5.0 web framework. The Django web application framework powers huge sites like Netflix, Dropbox, YouTube, and Spotify. Learn how it can power your web apps too! In this hands-on book, you’ll begin building a fully functional web application with Django starting with chapter 1. In Django in Action you’ll: • Build a multi-user web site in Django • Read, write, and manage data • Create reusable and composable HTML templates • Manage user data including form submissions and file uploads • Set up authentication, authorization, and per-person-per-page permissions • Manage the backend using the Django Admin tool • Discover Django libraries and plugins Django in Action is the perfect way to get started for new Django developers creating their first Python-based web apps. It’s written by Christopher Trudeau, co-host of The Real Python Podcast and creator of dozens of popular courses at Real Python and TalkPython. The book starts with Django’s basics and works through all of the core concepts of the framework until you’re comfortable and confident creating your own web apps. You’ll especially enjoy the author’s lighthearted style that makes learning fun! Foreword by Michael Kennedy. About the technology Django makes life easier for Python web developers. This “batteries included” framework comes packed with everything you need—a template engine that crafts HTML-like code, efficient user management features, automated testing, robust API support, and much more. If you know the basics of Python, Django will help you build professional-quality web applications. This book will show you how. About the book In Django in Action you’ll dive deep into Django as you build a complete multi-user website. Hands-on from the start, each chapter introduces new features to your site, including password management and authentication, web forms and file uploads, and dynamic, JavaScript-like interactivity. You’ll see how all the components of a Django project come together while learning practical tips on leveraging third-party libraries and deploying your code to production. What's inside • Reusable and composable HTML templates • Reading, writing, and managing data • Backend management with Django Admin • Exploring Django libraries and plugins About the reader For readers with basic Python programming and some HTML knowledge. About the author Christopher Trudeau is the co-host of the Real Python Podcast, a prolific author of Django and Python articles and video courses, and an experienced Python developer.

Author(s): Christopher Trudeau
Edition: 1
Publisher: Manning
Year: 2024

Language: English
Commentary: Publisher's PDF
Pages: 436
City: Shelter Island, NY
Tags: Python; Web Applications; SQLite; Django; Testing; User Management; Object Relational Mapping

Django in Action
brief contents
contents
foreword
preface
acknowledgments
about this book
How this book is organized: A roadmap
About the code
liveBook discussion forum
Other online resources
about the author
about the cover illustration
Part 1 Django essentials
1 Django unfolds
1.1 Django’s parts
1.1.1 Mapping URLs, Django views, and the MVC model
1.1.2 Databases: Dynamic sites need data
1.1.3 Structuring HTML for reuse
1.1.4 Multiuser sites
1.2 What can you do with Django?
1.2.1 Server-side, single-page, and mixed-page applications
1.2.2 When and where you should use it
1.2.3 Potential projects
1.2.4 The RiffMates project
Summary
2 Your first Django site
2.1 The RiffMates project
2.2 Creating a Django project
2.3 Projects vs. apps
2.4 Your first Django app
2.5 Your first Django view
2.6 Registering a route
2.7 Visiting your view
2.8 Exercises
Summary
3 Templates
3.1 Where to use templates
3.2 Context objects and the parts of a Template
3.3 Django shell
3.4 Rendering a Template
3.5 Common tags and filters
3.5.1 Conditional blocks
3.5.2 Looping blocks
3.5.3 Comment blocks
3.5.4 Verbatim blocks
3.5.5 Referencing URLs
3.5.6 Common filters
3.6 Using render() in a view
3.7 Escaping special characters
3.8 Composing templates out of blocks
3.8.1 Writing a base template file
3.8.2 Including an HTML snippet
3.9 Exercises
Summary
4 Django ORM
4.1 Interacting with a database
4.2 ORM Models
4.3 SQLite and dbshell
4.4 Model queries
4.4.1 Using .all() and .filter() to fetch QuerySet results
4.4.2 Field look-ups
4.5 Modifying your data
4.6 Querying models in views
4.6.1 Using URL arguments
4.6.2 Listing pages
4.6.3 Using query parameters for pagination
4.7 Model relations
4.7.1 One-to-many relationships
4.7.2 Many-to-many relationships
4.8 Model fields
4.8.1 Popular cross-field field options
4.8.2 Popular fields
4.9 Fixtures
4.10 Danger zone, or know thy SQL
4.11 Exercises
Summary
5 Django Admin
5.1 Touring the Django Admin
5.1.1 Creating an admin user
5.1.2 The default Django Admin
5.1.3 Adding your own models
5.2 Customizing a listing page
5.2.1 Sorting and searching
5.2.2 Filtering
5.2.3 New in Django 5: Facets
5.3 Cross-linking between related objects
5.4 Model Meta properties
5.4.1 Sort order
5.4.2 Indexes
5.4.3 Uniqueness
5.4.4 Object names
5.5 Exercises
Summary
Part 2 Django building blocks
6 User management
6.1 Multiuser websites
6.2 Storing user data
6.2.1 Choosing a user account mechanism
6.2.2 Adding a user profile
6.3 Restricting access to views
6.4 Authorization in views
6.4.1 Handling logouts
6.5 Using signals to automatically create a user profile
6.6 Password management
6.6.1 Password reset page
6.6.2 Password reset email
6.6.3 New password form
6.7 Exercises
Summary
7 Forms, user data, static files, and uploads
7.1 Web forms
7.1.1 Handling GET and POST in views
7.1.2 CSRF
7.1.3 Beautifying web forms
7.1.4 New in Django 5: Reusable field group templates
7.2 Django ModelForm
7.2.1 Validating fields in a model
7.2.2 A ModelAdmin for SeekingAd using Truncate
7.2.3 Writing a ModelForm
7.2.4 Using SeekingAdForm in a view
7.2.5 Editing existing data with forms
7.3 Serving static files
7.4 Uploads
7.4.1 Configuring your project for uploads
7.4.2 Storing and referencing uploaded files
7.4.3 File upload forms and views
7.4.4 Restricted file downloads
7.5 Exercises
Summary
8 Testing your project
8.1 Automated testing
8.1.1 The scope of tests
8.1.2 Automated testing in Python
8.2 Your first Django test
8.3 Testing with the database
8.4 Expecting errors
8.5 Authenticating and posting data
8.6 Testing with file uploads
8.7 More testing techniques
8.7.1 LiveServerTestCase for Selenium
8.7.2 Third-party helpers
8.8 Measuring tests and code quality
8.9 Exercises
Summary
9 Management commands
9.1 Management commands in practice
9.1.1 Built-in management commands
9.1.2 Changing a password
9.1.3 Configuration
9.1.4 Flushing the database
9.1.5 SQL commands
9.2 Writing your own management command
9.3 Handling arguments
9.3.1 Built-in arguments
9.4 Testing, and using STDOUT and STDERR
9.5 Exercises
Summary
10 Migration
10.1 Migration scripts in detail
10.1.1 An initial migration
10.1.2 Changing a model
10.2 Migration with existing data
10.3 Squashing a migration
10.4 More migration choices
10.5 Exercises
Summary
Part 3 Django projects
11 APIs
11.1 Why use an API?
11.1.1 CRUD and REST
11.1.2 Versioning an API
11.2 Building an API with Django Ninja
11.2.1 Serializing objects
11.2.2 Handling arguments
11.2.3 Filtering your listings
11.2.4 Nesting data
11.2.5 Authenticating your API
11.2.6 Creating objects with the API
11.2.7 Updating and deleting with the API
11.3 Other API libraries
11.4 Exercises
Summary
12 Making your pages more dynamic with HTMX
12.1 Dynamic web pages
12.2 HTMX attributes
12.3 Lazy loading
12.4 Search-as-you-type with infinite scroll
12.5 Click to edit
12.6 Exercises
Summary
13 Django power tools
13.1 Django Debug Toolbar
13.2 Tool libraries
13.2.1 Django Extensions
13.2.2 Django Awl
13.3 Look and feel
13.3.1 Django Grappelli
13.3.2 Crispy forms
13.3.3 Favicons
13.4 Feature flags
13.5 Static sites
Summary
14 Where to go next
14.1 Within Django
14.2 Configuration
14.3 Dealing with data
14.4 Web tools
14.5 Asynchronous actions
14.6 A wide world
appendix A Installation and setup
A.1 Installing Python
A.1.1 Windows installation options
A.2 Virtual environments
A.3 Editing tools
A.4 Installing third-party libraries
appendix B Django in a production environment
B.1 Parts of a web deployment
B.2 Server hosting vs. platform as a service
B.2.1 Virtual private servers
B.2.2 Platform as a service
B.3 Synchronous vs. asynchronous
B.4 Readying Django for production
B.4.1 Environment-specific configuration
B.4.2 Configuring email
B.4.3 Logging
B.4.4 Custom 404 and 500 pages
B.5 Static file management
B.6 Other databases
B.7 Caching
B.8 Putting it all together
B.8.1 Builds and releases
B.8.2 Monitoring
appendix C Django template tag and filter reference
C.1 Tags
C.1.1 Loadable tags
C.2 Filters
C.2.1 Loadable filters
appendix D Django ORM field reference
D.1 Field options
D.2 Field types
D.3 Relationship field types
D.3.1 ForeignKey
D.3.2 ManyToManyField
D.3.3 OneToOneField
appendix E Sample exercise solutions
E.1 Chapter 2
E.2 Chapter 3
E.3 Chapter 4
E.4 Chapter 5
E.5 Chapter 6
E.6 Chapter 7
E.7 Chapter 8
E.8 Chapter 9
E.9 Chapter 10
E.10 Chapter 11
E.11 Chapter 12
index
Symbols
Numerics
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
Z
Django in Action - back