Covers 1.11 LTS, compatible with Python 2 and 3
Daniel Rubio
At a Glace
Introduction to the Django Framework
Django Urls and Views
Django Templates
Jinja Templates in Django
Django Application Management
Django Forms
Django Models
Django Model Queries and Managers
Django Model Forms and Class Views
Django User Management
Django admin Management
REST Services with Django
Appendix A: Python Basics
Book Details
Price
|
2.50 USD |
---|---|
Pages
| 609 p |
File Size
|
10,829 KB |
File Type
|
PDF format |
ISBN-13 (pbk) ISBN-13 (electronic)
| 978-1-4842-2786-2 978-1-4842-2787-9 |
Copyright
| 2017 by Daniel Rubio |
Daniel Rubio has worked in software development for over 15 years, in roles that include developer,
software architect, manager, consultant, and CTO. He has worked with startups, government agencies, as well as corporations in industries that include banking, education, social media, and retail.
He has coauthored the best-selling Spring Recipes book and other titles for Apress (2010), in addition to writing for various other online publications. Daniel’s expertise in the early part of his career was focused on Java, Linux, and open source technology, whereas more recently he has focused on Python, JavaScript, and Cloud technology.
About the Technical Reviewer
Tri Phan is the founder of Programming Learning Channel on YouTube. He has over 7 years of experience in the software industry. Specifically, he has worked in many outsourcing companies and has written many applications of many fields in different programming languages such as PHP, Java, and C #. In addition, he has over 6 years of experience in teaching at international and technological centers such as Aptech, NIIT, and Kent College.
Introduction
The web framework market is an extremely competitive environment, with many programming languages and framework design philosophies to choose from. But if you need to build web-based software with quick turnaround times and a scripting language, there’s a high probability the Django framework – or something built with it – will be your top choice.
Django has competitors, but even its nearest competitor in the Python ecosystem, the Flask framework
has about one-fourth the mind share of Django, based on the benchmark of worldwide Google searches
made for Django vs. Flask.1 Outside the Python ecosystem, but still in the scripting language segment, the Ruby on Rails framework – which emerged along the same time as Django and follows a similar design philosophy – has always maintained an almost equal mind share with Django, as it can also be proven by the amount of worldwide Google search activity.
So what makes the Django framework such a strong choice for web development? It provides a rapid
development foundation to create complex web applications. A rapidness that is provided by a modular
and simple philosophy of not repeating constructs and logic throughout a project’s structure (a.k.a. the DRY principle or Don’t Repeat Yourself principle).
And it’s this DRY principle, which has given way to a thriving community, as well as a multitude of
packages and other frameworks based on the Django framework. Over 10 years after its initial release, there’s now a full-fledged CMS (Content Management System), a turn-key e-commerce platform and over 3000 packages, all built or designed to work with the Django framework. Not to mention, there are two annual conferences in the United States and Europe to showcase Django innovations.
This book will walk you through the many core concepts associated with the Django framework. It will
help you learn standard and best practices that are essential to creating effective Django projects. And if and when you use a Django-based package or framework, these same foundations will help you navigate the more complex concepts and avoid any blind spots that are part of the core Django framework.
Table of Contents
About the Author ....................................................................................................xxi
About the Technical Reviewer ..............................................................................xxiii
Acknowledgments .................................................................................................xxv
Introduction .........................................................................................................xxvii
■■Chapter 1: Introduction to the Django Framework ................................................ 1
Django Framework Design Principles .............................................................................. 2
Don’t Repeat Yourself (DRY) Principle .....................................................................................................2
Explicit Is Better Than Implicit ................................................................................................................4
Loosely Coupled Architecture .................................................................................................................5
Install Django ................................................................................................................... 5
Install Python (Prerequisite) ....................................................................................................................6
Update or Install pip Package Manager (Prerequisite) ........................................................................... 7
Install virtualenv (Optional Prerequisite) .................................................................................................8
Install Django ........................................................................................................................................11
Install Django from Git ..........................................................................................................................11
Start a Django Project .................................................................................................... 13
Set Up a Database for a Django Project ......................................................................... 15
Install Python Database Packages ........................................................................................................18
Test Django Database Connection and Build Django Base Tables ........................................................ 18
Set Up Content: Understand Urls, Templates, and Apps ................................................. 19
Create and Configure Django Urls ........................................................................................................20
Create and Configure Django Templates .............................................................................................. 21
Create and Configure Django Apps .......................................................................................................22
Set Up the Django admin Site ........................................................................................ 25
Configure and Install the Django admin site App ..................................................................................25
Configure and Install the Django admin site docs App ......................................................................... 28
■■Chapter 2: Django Urls and Views ....................................................................... 31
Url Regular Expressions ................................................................................................. 31
Precedence Rule: Granular Urls First, Broad Urls Last ..........................................................................31
Exact Url Patterns: Forgoing Broad Matching .......................................................................................32
Common Url Patterns ...........................................................................................................................33
Url Parameters, Extra Options, and Query Strings .......................................................... 35
Url Consolidation and Modularization ............................................................................. 38
Url Naming and Namespaces ......................................................................................... 40
View Method Requests ................................................................................................... 47
View Method Responses ................................................................................................ 49
Response Options for HTTP Status and Content-Type Headers ............................................................ 50
Built-In Response Shortcuts and Templates for Common HTTP Status: 404 (Not Found),
500 (Internal Server Error), 400 (Bad Request), and 403 (Forbidden) ................................................... 51
Built-In Response Shortcuts for Inline and Streamed Content ............................................................. 55
View Method Middleware ............................................................................................... 57
Built-In Middleware Classes .................................................................................................................57
Middleware Structure and Execution Process ...................................................................................... 60
Middleware Flash Messages in View Methods .............................................................. 64
Add Flash Messages .............................................................................................................................65
Access Flash Messages .......................................................................................................................67
Class-Based Views ......................................................................................................... 68
Built-In Class-Based Views ...................................................................................................................69
Class-Based View Structure and Execution .......................................................................................... 69
■■Chapter 3: Django Templates ............................................................................... 73
Django Template Syntax ................................................................................................. 73
Auto-Escaping: HTML and Erring on the Safe Side ............................................................................... 74
Django Template Configuration ...................................................................................... 75
Template Search Paths .........................................................................................................................76
Invalid Template Variables ....................................................................................................................78
Debug Output ........................................................................................................................................80
Auto-Escape .........................................................................................................................................81
File charset ...........................................................................................................................................82
Automatic Access to Custom Template tag/filter Modules ................................................................... 83
Template Loaders .................................................................................................................................84
Create Reusable Templates ............................................................................................ 85
Built-In Context Processors ............................................................................................ 87
Django debug context processor (django.template.context_processors.debug) .................................. 88
Django request context processor (django.template.context_processors.request) ............................. 88
Django auth context processor (django.contrib.auth.context_processors.auth) .................................. 88
Django messages context processor (django.contrib.messages.context_processors.messages) ....... 89
Other Built-In Django Context Processors: i18n, media, static, tz, and CSRF context Processors ........ 89
Custom Context Processors ........................................................................................... 90
Built-In Django Filters .................................................................................................... 91
Dates ....................................................................................................................................................91
Strings, Lists, and Numbers ..................................................................................................................94
Numbers ...............................................................................................................................................95
Strings ..................................................................................................................................................96
Lists and Dictionaries ...........................................................................................................................98
Spacing and Special Characters ...........................................................................................................99
Development and Testing ...................................................................................................................100
Urls .....................................................................................................................................................101
Built-In Django Tags ..................................................................................................... 101
Dates ..................................................................................................................................................102
Forms .................................................................................................................................................102
Comparison Operations ......................................................................................................................102
Loops ..................................................................................................................................................104
Python and Filter Operations ..............................................................................................................107
Spacing and Special Characters .........................................................................................................108
Template Structures ...........................................................................................................................109
Development and Testing ...................................................................................................................110
Urls .....................................................................................................................................................110
Custom Filters .............................................................................................................. 110
Structure .............................................................................................................................................110
Options: Naming, HTML, and What Comes In and Out ........................................................................ 112
Installation and Access .......................................................................................................................114
■■Chapter 4: Jinja Templates in Django ................................................................ 117
Jinja Advantages and Disadvantages ........................................................................... 117
Transition to Jinja Templates from Django Templates .................................................. 118
What Works the Same Way in Jinja and Django Templates ................................................................ 118
What Works Differently in Jinja Templates Compared to Django Templates ...................................... 119
New Concepts and Features in Jinja Templates vs. Django Templates .............................................. 121
Jinja Template Configuration in Django ........................................................................ 123
Template Search Paths .......................................................................................................................123
Auto-Escaping Behavior .....................................................................................................................125
Auto-Reload Template Behavior and Caching ..................................................................................... 126
Invalid Template Variables ..................................................................................................................127
Template Loaders ...............................................................................................................................128
Create Reusable Jinja Templates ................................................................................. 128
Jinja Globals: Access Data on All Jinja Templates, Like Django Context Processors ....... 134
Jinja Built-In Statements/Tags and Functions (Like Django Template Tags) ................ 135
Comparison Operations ......................................................................................................................136
Loops ..................................................................................................................................................137
Python and Filter Operations ..............................................................................................................141
Spacing and Special Characters .........................................................................................................142
Template Structures ...........................................................................................................................145
Jinja Built-In Filters and Tests (Like Django Filters) ..................................................... 146
Strings, Lists, Dictionaries, Numbers, and Objects ............................................................................. 147
Strings and Lists .................................................................................................................................148
Dictionaries and Objects .....................................................................................................................149
Strings ................................................................................................................................................151
Numbers .............................................................................................................................................152
Spacing and Special Characters .........................................................................................................153
Development and Testing ...................................................................................................................155
Urls .....................................................................................................................................................155
Custom Filters and Tests in Jinja .................................................................................. 156
Structure .............................................................................................................................................156
Installation and Access .......................................................................................................................157
Jinja Extensions ........................................................................................................... 158
Enable Jinja Extensions ......................................................................................................................159
Create Jinja Extensions ......................................................................................................................160
Jinja Policies ................................................................................................................ 161
■■Chapter 5: Django Application Management ..................................................... 163
Django settings.py for the Real World .......................................................................... 163
Switch DEBUG to False .......................................................................................................................163
Define ALLOWED_HOSTS ....................................................................................................................164
Be Careful with the SECRET_KEY Value .............................................................................................. 165
Define Administrators for ADMINS and MANAGERS ........................................................................... 165
Use Dynamic Absolute Paths ..............................................................................................................166
Use Multiple Environments or Configuration Files for Django ............................................................ 168
Set Up Static Web Page Resources - Images, CSS, JavaScript .................................... 173
Set Up Static Resources in a Development Environment (DEBUG=False) .......................................... 173
Access Static Resources in Django Templates ................................................................................... 176
Access Static Resources in Jinja Templates ...................................................................................... 178
Set Up Static Resources in a Production Environment (DEBUG=True) ............................................... 178
Django Logging ............................................................................................................ 179
Python Core Logging Concepts ...........................................................................................................180
Django Default Logging ......................................................................................................................180
Create Log Messages .........................................................................................................................183
Custom Logging ..................................................................................................................................185
Logging with Sentry ...........................................................................................................................190
Django Email Service ................................................................................................... 193
Set Up a Default Connection to an Email Server ................................................................................ 193
Set Up a Default Connection to Third-Party Email Providers .............................................................. 194
Built-In Helpers to Send Email ............................................................................................................197
Custom Email: Attachments, Headers, CC, BCC, and More with EmailMessage ................................. 199
Debug Django Applications .......................................................................................... 203
Django Shell: Python manage.py Shell ...............................................................................................204
Django Debug Toolbar .........................................................................................................................204
Django pdb .........................................................................................................................................206
Django Extensions ..............................................................................................................................208
Django Management Commands ................................................................................. 211
Custom Management Command Structure ........................................................................................ 212
Custom Management Command Installation ...................................................................................... 214
Management Command Automation .................................................................................................. 215
■■Chapter 6: Django Forms ................................................................................... 217
Django Form Structure and Workflow .......................................................................... 217
Functional Web Form Syntax for Django Forms ................................................................................. 219
Django View Method to Process Form (POST Handling) ..................................................................... 220
CSRF: What Is It and How Does It Work with Django? ........................................................................ 222
Django Form Processing: Initialization, Field Access, Validation,
and Error Handling ....................................................................................................... 224
Initialize Forms: Initial for Fields and Forms, __init__ method, label_suffix, auto_id,
field_order, and use_required_attribute .............................................................................................225
Accessing Form Values: request.POST and cleaned_data .................................................................. 229
Validating Form Values: is_valid(), validators, clean_<field>(), and clean() ....................................... 230
Error Form Values: Errors ....................................................................................................................234
Django Form Field Types: Widgets, Options, and Validations ........................................ 235
The Relationship between Widgets and Form Fields .......................................................................... 245
Empty, Default, and Predetermined Values: Required, Initial, and Choices ......................................... 246
Limiting Text Values: max_length, min_length, strip, and Validators .................................................. 246
Limiting Number Values: max_value, min_value, max_digits, decimal_places, and Validators ......... 247
Error Messages: error_messages .......................................................................................................247
Field Layout Values: label, label_suffix, help_text .............................................................................. 248
Set Up the Layout for Django Forms in Templates ....................................................... 248
Output Form Fields: form.as_table, form.as_p, form.as_ul, and Granularly by Field ......................... 249
Output Field Order: field_order and order_fields ................................................................................ 252
Output CSS Classes, Styles, and Field Attributes: error_css_class, required_css_class, Widget,
Customization, and Various Form Field Options ................................................................................. 252
Output Form Field Errors: form.<field_name>.errors, form.errors, form.non_field_errors ............... 254
Django Custom Form Fields and Widgets ..................................................................... 255
Create Custom Form Fields ................................................................................................................256
Customize Built-In Widgets ................................................................................................................ 257
Create Custom Form Widgets ............................................................................................................. 258
Custom Form Widget Configuration Options ....................................................................................... 260
Django Advanced Form Processing: Partial Forms, AJAX, and Files ............................ 261
Partial Forms ......................................................................................................................................261
AJAX Form Submission ......................................................................................................................263
Files in Forms .....................................................................................................................................265
Django Formsets .......................................................................................................... 268
Formset Factory .................................................................................................................................270
Formset Management Form and Formset Processing ....................................................................... 270
Formset Custom Validation and Formset Errors ................................................................................. 272
■■Chapter 7: Django Models ................................................................................. 275
Django Models and the Migrations Workflow ............................................................... 275
Create Django Models ........................................................................................................................276
Migrations and the Django Model Workflow ....................................................................................... 277
Django Model Data Types ............................................................................................. 280
Limiting Values: max_length, min_value, max_value, max_digits, and decimal_places .................... 287
Empty, Null and Not Null Values: Blank and Null .................................................................................288
Predetermined Values: default, auto_now, auto_now_add, and choices ........................................... 290
Unique values: unique, unique_for_date, unique_for_month and unique_for_year ........................... 293
Form Values: Editable, help_text, verbose_name, and error_messages ............................................ 293
Database Definition Language (DDL) Values: db_column, db_index, db_tablespace, primary_key ... 294
Built-In and Custom Validators: Validators ..........................................................................................295
Django Model Default and Custom Behaviors .............................................................. 296
Model Methods ...................................................................................................................................296
Model Manager Field: Objects ............................................................................................................304
Model Meta Class and Options ...........................................................................................................305
Relationships in Django Models ................................................................................... 310
One to Many Relationships in Django Models ....................................................................................311
Many to Many Relationships in Django Models ..................................................................................311
One to One Relationships in Django Models ....................................................................................... 312
Options for Relationship Model Data Types ........................................................................................ 313
Django Model Transactions .......................................................................................... 317
Transaction per Request: ATOMIC_REQUESTS and Decorators .......................................................... 317
Context Manager and Callbacks: atomic() and on_commit() .............................................................. 318
Django Model Migrations ............................................................................................. 319
Migration File Creation .......................................................................................................................319
Migration File Renaming ....................................................................................................................320
Migration File Squashing ....................................................................................................................321
Migration File Structure ......................................................................................................................322
Migration File Rollback .......................................................................................................................323
Django Model Database Tasks ..................................................................................... 323
Backup Data: Fixtures, dumpdata, loaddata, and inspectdb ............................................................... 324
Delete Data: Flush, sqlflush, and sqlsequencereset ........................................................................... 324
Interact with Data: dbshell ..................................................................................................................325
Django Model Initial Data Setup ................................................................................... 325
Hard-code predefined records in Python migration file ..................................................................... 325
SQL script with SQL statements .........................................................................................................326
Django fixture file ...............................................................................................................................328
Django Model Signals ................................................................................................... 329
Built-In Django Model Signals ............................................................................................................330
Listen for Django Model Signals .........................................................................................................330
Emit Custom Signals in Django Model Signals ...................................................................................333
Django Models Outside of models.py ........................................................................... 334
Django Models Inside Apps in the Models Folder ............................................................................... 334
Django Models Inside Apps in Custom Folders ...................................................................................335
Django Models Outside Apps and Model Assignment to Other Apps .................................................. 336
Django Models and Multiple Databases ....................................................................... 336
Multiple Databases for Django Models: using .................................................................................... 337
Multiple Databases for Django Tools: --database ............................................................................... 337
Multiple Database Routers: DATABASE_ROUTERS setting .................................................................. 337
■■Chapter 8: Django Model Queries and Managers .............................................. 341
CRUD Single Records in Django Models ....................................................................... 341
Create a Single Record with save() or create() ...................................................................................341
Read a Single Record with get() or get_or_create() ........................................................................... 343
Update a Single Record with save(), update(), update_or_create(), or refresh_from_db() ................. 345
Delete a Single Record with delete() ..................................................................................................347
CRUD Multiple Records in Django Models .................................................................... 348
Create Multiple Records with bulk_create() ....................................................................................... 349
Read Multiple Records with all(), filter(), exclude(), or in_bulk() ......................................................... 351
Understanding a QuerySet: Lazy Evaluation and Caching .................................................................. 353
Read Performance Methods: defer(), only(), values(), values_list(), iterator(), exists(), and none() ..... 356
Update Multiple Records with update() or select_for_update() .......................................................... 359
Delete Multiple Records with delete() ................................................................................................361
CRUD Relationship Records Across Django Models ..................................................... 361
One to Many CRUD Operations ...........................................................................................................361
Many to Many CRUD Operations .........................................................................................................365
One to One CRUD Operations ..............................................................................................................367
Read Performance Relationship Methods: select_related() and prefetch_related() ........................... 368
Model Queries by SQL Keyword ................................................................................... 370
WHERE Queries: Django Field Lookups ...............................................................................................370
DISTINCT Queries ................................................................................................................................377
ORDER Queries: order_by() and reverse() ...........................................................................................379
LIMIT Queries ......................................................................................................................................380
Merge Queries ....................................................................................................................................381
Aggregation Queries ...........................................................................................................................384
Expression and Function Queries .......................................................................................................387
Model Queries with Raw (Open-Ended) SQL ................................................................ 392
SQL Queries with a Model Manager’s raw() Method .......................................................................... 393
SQL Queries with Python’s DB API ......................................................................................................395
Model Managers ........................................................................................................... 396
Custom and Multiple Model Managers ...............................................................................................397
Custom Model Managers and QuerySet Classes with Methods ......................................................... 398
Custom Reverse Model Managers for Related Models ....................................................................... 401
■■Chapter 9: Django Model Forms and Class Views ............................................. 403
Django Model Form Structure and Workflow ............................................................... 403
Create Django Model Forms ......................................................................................... 404
Django Model Form Options and Field Mapping .......................................................... 405
Model Form Required Options: Model and Fields or Exclude ............................................................. 405
Model Form Default Field Mapping ....................................................................................................406
Model Form New and Custom Fields: Widgets, Labels, help_texts, error_messages,
field_classes, and localize_fields .......................................................................................................408
Django Model Forms with Relationships ...................................................................... 410
ModelChoiceField and ModelMultipleChoiceField Form Field Options: queryset, empty_label,
to_field_name, and label_from_instance ........................................................................................... 410
Django Model Form Processing ................................................................................... 413
Model Form Initialization: Initial and Instance ....................................................................................413
Model Form Validation ........................................................................................................................414
Django Model Formsets ............................................................................................... 416
Model Formset Factory .......................................................................................................................416
Class-Based Views with Models .................................................................................. 417
Create Model Records with the Class-Based View CreateView .......................................................... 418
CreateView Fields and Methods .........................................................................................................420
Read Model Records with the Class-Based Views ListView and DetailView ...................................... 426
ListView Fields and Methods ..............................................................................................................428
DetailView Fields and Methods ..........................................................................................................431
Update Model Records with the Class-Based View UpateView .......................................................... 433
UpdateView Fields and Methods ........................................................................................................435
Delete Records with the Class-Bases View DeleteView ..................................................................... 436
DeleteView Fields and Methods .........................................................................................................437
Class-Based Views with Mixins ..........................................................................................................438
■■Chapter 10: Django User Management .............................................................. 441
Introduction to the Django User System ....................................................................... 441
User Types, Subtypes, Groups, and Permissions ................................................................................ 441
Create Users .......................................................................................................................................442
Manage Users .....................................................................................................................................445
Create and Manage Groups ................................................................................................................450
Permission Types ......................................................................................................... 452
User Permissions: Superuser, Staff, and Active .................................................................................. 453
Model Permissions: Add, Change, Delete, and Custom ....................................................................... 453
Permission Checks and Enforcement ........................................................................... 455
View Method Permission Checks .......................................................................................................455
URL Permission Checks ......................................................................................................................458
Template Permission Checks ..............................................................................................................459
Class-Based View Permission Checks ................................................................................................ 460
User Authentication and Auto-Management ................................................................ 462
Login and Logout Workflow ................................................................................................................463
Password Change Workflow ...............................................................................................................464
Password Reset Workflow ..................................................................................................................464
User Signup Workflow ........................................................................................................................465
Custom User Model Fields ............................................................................................ 467
Custom Authentication Back Ends ............................................................................... 469
User Management with Django allauth ........................................................................ 471
Install and Set Up django-allauth .......................................................................................................471
First Log In and Log Out with Superuser in Django allauth ................................................................ 473
User Signup with Django allauth ........................................................................................................475
Password Reset and Change with Django allauth .............................................................................. 475
Add and Change User Email with Django allauth ............................................................................... 476
Change Templates for Django allauth ................................................................................................. 477
Models and Database Tables Behind Django allauth .......................................................................... 477
Social Authentication with Django allauth .................................................................... 478
Set Up Django allauth for Different Social Providers .......................................................................... 478
Set Up Facebook with Django allauth .................................................................................................480
Set Up Google with Django allauth .....................................................................................................486
Set Up Twitter with Django allauth .....................................................................................................491
■■Chapter 11: Django admin Management ........................................................... 495
Set Up Django Models in the Django admin ................................................................. 495
Django admin Read Record Options ............................................................................. 496
Record Display: list_display, format_html, empty_value_display ...................................................... 498
Record Order: admin_order_field and ordering ..................................................................................502
Record Links and Inline Edit: list_display_links and list_editable ...................................................... 503
Record Pagination: list_per_page, list_max_show_all, paginator ...................................................... 506
Record Search: search_fields, list_filter, show_full_result_count, preserve_filters .......................... 507
Record Dates: date_hierarchy ............................................................................................................512
Record Actions: actions_on_top, actions_on_bottom, actions ........................................................... 514
Record Relationships ..........................................................................................................................514
Django admin Create, Update, Delete Record Options .................................................. 519
Record Forms: fields, readonly_fields, exclude, fieldsets, formfield_overrides, form,
prepopulated_fields ............................................................................................................................520
Actions, Links, and Positions: save_on_top, save_as(Clone records),
save_as_continue and view_on_site ................................................................................................. 527
Relationships: filter_horizontal, filter_vertical, radio_fields, raw_id_fields, inlines ........................... 529
Django admin Custom Page Layout, Data, and Behaviors ............................................ 536
Django admin Custom Global Values for Default Templates ............................................................... 536
Django admin Custom Page Layout with Custom Templates ............................................................. 538
Django admin Custom Static Resources ............................................................................................540
Django admin Custom Data and Behaviors with admin Class Fields and Methods ............................ 541
Django admin CRUD Permissions ................................................................................. 543
Multiple Django admin Sites ........................................................................................ 545
■■Chapter 12: REST Services with Django ............................................................ 549
REST Services in Django .............................................................................................. 549
Standard View Method Designed as REST Service ............................................................................. 550
Django REST Framework ....................................................................................................................554
Django Tastypie Framework ...............................................................................................................554
Django REST Framework Concepts and Introduction ................................................... 555
Serializers and Views .........................................................................................................................555
Class-Based Views .............................................................................................................................558
Mixins and Generic Class-Based Views ..............................................................................................559
View Sets and Routers .......................................................................................................................560
Django REST Framework Security ............................................................................... 562
Set Up REST Framework Services Permissions ................................................................................. 562
Set Up REST Framework Login Page .................................................................................................. 565
■■Appendix A: Python Basics ................................................................................ 567
Strings, Unicode, and Other Annoying Text Behaviors .................................................. 567
Methods Arguments: Default, optional, *args, and **kwargs ....................................... 571
Classes and Subclasses ............................................................................................... 574
Loops, Iterators, and Generators .................................................................................. 576
List Comprehensions, Generator Expressions, Maps, and Filters ................................. 581
Lambda Keyword for Anonymous Methods .................................................................. 583
Index ..................................................................................................................... 585
Cover image by Freepik (www.freepik.com).
Managing Director: Welmoed Spahr
Editorial Director: Todd Green
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Technical Reviewer: Tri Phan
Coordinating Editor: Mark Powers
Copy Editor: Karen Jameson