شروع با جنگو: توسعه و استقرار برنامههای وب با پایتون
Beginning Django : Web Application Development and Deployment with Python
معرفی کتاب «شروع با جنگو: توسعه و استقرار برنامههای وب با پایتون» (با عنوان لاتین Beginning Django : Web Application Development and Deployment with Python) نوشتهٔ Rubio, Daniel، منتشرشده توسط نشر Apress : Imprint: Apress در سال 2017. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است.
Discover the Django web application framework and get started building Python-based web applications. This book takes you from the basics of Django all the way through to cutting-edge topics such as creating RESTful applications. __Beginning Django__ also covers ancillary, but essential, development topics, including configuration settings, static resource management, logging, debugging, and email. Along with material on data access with SQL queries, you’ll have all you need to get up and running with Django 1.11 LTS, which is compatible with Python 2 and Python 3. Once you’ve built your web application, you’ll need to be the admin, so the next part of the book covers how to enforce permission management with users and groups. This technique allows you to restrict access to URLs and content, giving you total control of your data. In addition, you’ll work with and customize the Django admin site, which provides access to a Django project’s data. After reading and using this book, you’ll be able to build a Django application top to bottom and be ready to move on to more advanced or complex Django application development. **What You'll Learn** * Get started with the Django framework * Use Django views, class-based views, URLs, middleware, forms, templates, and Jinja templates * Take advantage of Django models, including model relationships, migrations, queries, and forms * Leverage the Django admin site to get access to the database used by a Django project * Deploy Django REST services to serve as the data backbone for mobile, IoT, and SaaS systems **Who This Book Is For** Python developers new to the Django web application development framework and web developers new to Python and Django. Contents at a Glance......Page 5 Contents......Page 6 About the Author......Page 20 About the Technical Reviewer......Page 21 Acknowledgments......Page 22 Introduction......Page 23 Chapter 1: Introduction to the Django Framework......Page 24 Don’t Repeat Yourself (DRY) Principle......Page 25 Explicit Is Better Than Implicit......Page 27 Install Django......Page 28 Install Python (Prerequisite)......Page 29 Update or Install pip Package Manager (Prerequisite)......Page 30 Install virtualenv (Optional Prerequisite)......Page 31 Install Django from Git......Page 34 Start a Django Project......Page 36 Set Up a Database for a Django Project......Page 38 Test Django Database Connection and Build Django Base Tables......Page 41 Set Up Content: Understand Urls, Templates, and Apps......Page 42 Create and Configure Django Urls......Page 43 Create and Configure Django Templates......Page 44 Create and Configure Django Apps......Page 45 Configure and Install the Django admin site App......Page 48 Configure and Install the Django admin site docs App......Page 51 Precedence Rule: Granular Urls First, Broad Urls Last......Page 53 Exact Url Patterns: Forgoing Broad Matching......Page 54 Common Url Patterns......Page 55 Url Parameters, Extra Options, and Query Strings......Page 57 Url Consolidation and Modularization......Page 60 Url Naming and Namespaces......Page 62 View Method Requests......Page 69 View Method Responses......Page 71 Response Options for HTTP Status and Content-Type Headers......Page 72 Built-In Response Shortcuts and Templates for Common HTTP Status: 404 (Not Found), 500 (Internal Server Error), 400 (Bad Request), and 403 (Forbidden)......Page 73 Built-In Response Shortcuts for Inline and Streamed Content......Page 77 Built-In Middleware Classes......Page 79 Middleware Structure and Execution Process......Page 82 Middleware Flash Messages in View Methods......Page 86 Add Flash Messages......Page 87 Access Flash Messages......Page 89 Class-Based Views......Page 90 Class-Based View Structure and Execution......Page 91 Django Template Syntax......Page 95 Auto-Escaping: HTML and Erring on the Safe Side......Page 96 Django Template Configuration......Page 97 Template Search Paths......Page 98 Invalid Template Variables......Page 100 Debug Output......Page 102 Auto-Escape......Page 103 File charset......Page 104 Automatic Access to Custom Template tag/filter Modules......Page 105 Template Loaders......Page 106 Create Reusable Templates......Page 107 Built-In Context Processors......Page 109 Django auth context processor (django.contrib.auth.context_processors.auth)......Page 110 Django static context processor (django.template.context_processors.static)......Page 111 Custom Context Processors......Page 112 Dates......Page 113 Strings, Lists, and Numbers......Page 116 Numbers......Page 117 Strings......Page 118 Lists and Dictionaries......Page 120 Spacing and Special Characters......Page 121 Development and Testing......Page 122 Built-In Django Tags......Page 123 Comparison Operations......Page 124 Loops......Page 126 Python and Filter Operations......Page 129 Spacing and Special Characters......Page 130 Template Structures......Page 131 Structure......Page 132 Options: Naming, HTML, and What Comes In and Out......Page 134 Installation and Access......Page 136 Jinja Advantages and Disadvantages......Page 138 What Works the Same Way in Jinja and Django Templates......Page 139 Filters......Page 140 {% for %} loop variables......Page 141 More useful built-in filters, tests, and more resemblance to a Python environment......Page 142 Line statements......Page 143 Template Search Paths......Page 144 Auto-Escaping Behavior......Page 146 Auto-Reload Template Behavior and Caching......Page 147 Invalid Template Variables......Page 148 Create Reusable Jinja Templates......Page 149 Jinja Globals: Access Data on All Jinja Templates, Like Django Context Processors......Page 155 Jinja Built-In Statements/Tags and Functions (Like Django Template Tags)......Page 156 Comparison Operations......Page 157 Loops......Page 158 Python and Filter Operations......Page 162 Spacing and Special Characters......Page 163 Template Structures......Page 166 Strings, Lists, Dictionaries, Numbers, and Objects......Page 167 Strings and Lists......Page 168 Dictionaries and Objects......Page 170 Numbers......Page 172 Spacing and Special Characters......Page 173 Structure......Page 176 Installation and Access......Page 177 Jinja Extensions......Page 179 Create Jinja Extensions......Page 180 Jinja Policies......Page 182 Switch DEBUG to False......Page 183 Define ALLOWED_HOSTS......Page 184 Define Administrators for ADMINS and MANAGERS......Page 185 Use Dynamic Absolute Paths......Page 186 Option 1) Multiple environments in the same settings.py file with a control variable......Page 188 Option 2) Multiple environment files using configparser......Page 190 Option 3) Multiple settings.py files with different names for each environment......Page 192 Set Up Static Resources in a Development Environment (DEBUG=False)......Page 193 Access Static Resources in Django Templates......Page 196 Set Up Static Resources in a Production Environment (DEBUG=True)......Page 198 Django Logging......Page 199 Django Default Logging......Page 200 Create Log Messages......Page 203 Custom Logging......Page 205 Disable default Django logging configuration......Page 206 Logging formatters: Message output......Page 207 Logging handlers: Locations, classes, filters, and logging thresholds......Page 208 Disable email to ADMINS on errors......Page 209 Set up Sentry the application......Page 210 Set up a Django application to use Sentry......Page 212 Set Up a Default Connection to an Email Server......Page 213 Set Up a Default Connection to Third-Party Email Providers......Page 214 Email with Google Gmail/Google Apps......Page 215 Email with SparkPost......Page 216 Built-In Helpers to Send Email......Page 217 Custom Email: Attachments, Headers, CC, BCC, and More with EmailMessage......Page 219 Debug Django Applications......Page 223 Django Debug Toolbar......Page 224 Django pdb......Page 226 Django Extensions......Page 228 Django Management Commands......Page 231 Custom Management Command Structure......Page 232 Custom Management Command Installation......Page 234 Management Command Automation......Page 235 Django Form Structure and Workflow......Page 237 Functional Web Form Syntax for Django Forms......Page 239 Django View Method to Process Form (POST Handling)......Page 240 CSRF: What Is It and How Does It Work with Django?......Page 242 Django Form Processing: Initialization, Field Access, Validation, and Error Handling......Page 244 Initialize Forms: Initial for Fields and Forms, __init__ method, label_suffix, auto_id, field_order, and use_required_attribute......Page 245 Accessing Form Values: request.POST and cleaned_data......Page 249 Validating Form Values: is_valid(), validators, clean_ (), and clean()......Page 250 Error Form Values: Errors......Page 254 Django Form Field Types: Widgets, Options, and Validations......Page 255 The Relationship between Widgets and Form Fields......Page 265 Limiting Text Values: max_length, min_length, strip, and Validators......Page 266 Error Messages: error_messages......Page 267 Set Up the Layout for Django Forms in Templates......Page 268 Output Form Fields: form.as_table, form.as_p, form.as_ul, and Granularly by Field......Page 269 Output CSS Classes, Styles, and Field Attributes: error_css_class, required_css_class, Widget, Customization, and Various Form Field Options......Page 272 Output Form Field Errors: form. .errors, form.errors, form.non_field_errors......Page 274 Django Custom Form Fields and Widgets......Page 275 Create Custom Form Fields......Page 276 Customize Built-In Widgets......Page 277 Create Custom Form Widgets......Page 278 Custom Form Widget Configuration Options......Page 280 Partial Forms......Page 281 AJAX Form Submission......Page 283 Files in Forms......Page 285 Django Formsets......Page 288 Formset Management Form and Formset Processing......Page 290 Formset Custom Validation and Formset Errors......Page 292 Django Models and the Migrations Workflow......Page 295 Create Django Models......Page 296 Migrations and the Django Model Workflow......Page 297 Django Model Data Types......Page 300 Limiting Values: max_length, min_value, max_value, max_digits, and decimal_places......Page 307 Empty, Null and Not Null Values: Blank and Null......Page 308 Predetermined Values: default, auto_now, auto_now_add, and choices......Page 310 Form Values: Editable, help_text, verbose_name, and error_messages......Page 313 Database Definition Language (DDL) Values: db_column, db_index, db_tablespace, primary_key......Page 314 Built-In and Custom Validators: Validators......Page 315 save() method......Page 316 Validation methods: clean_fields(), clean(), validate_unique() and full_clean()......Page 319 Data loading methods: Refresh_from_db(), from_db(), and get_deferred_fields() methods......Page 323 Model Manager Field: Objects......Page 324 Database Definition Language (DDL) table options: db_table, db_tablespace, managed, required_db_vendor, required_db_features and unique_together......Page 325 Database Definition Language (DDL) index options: Indexes and index_together......Page 326 Naming convention options: verbose_name, verbose_name_plural, label, label_lower, and app_label......Page 327 Inheritance Meta options: Abstract and proxy......Page 328 Query Meta options: Ordering, order_with_respect_to, get_latest_by, default_manager_name, base_manager_name, default_related_name, and select_on_save......Page 329 Relationships in Django Models......Page 330 Many to Many Relationships in Django Models......Page 331 One to One Relationships in Django Models......Page 332 Data integrity options: on_delete......Page 333 Reverse relationships: related_name, related_query_name, and symmetrical......Page 334 Form values: limit_choices_to......Page 336 Transaction per Request: ATOMIC_REQUESTS and Decorators......Page 337 Context Manager and Callbacks: atomic() and on_commit()......Page 338 Migration File Creation......Page 339 Migration File Renaming......Page 340 Migration File Squashing......Page 341 Migration File Structure......Page 342 Django Model Database Tasks......Page 343 Delete Data: Flush, sqlflush, and sqlsequencereset......Page 344 Hard-code predefined records in Python migration file......Page 345 SQL script with SQL statements......Page 346 Django fixture file......Page 348 Django Model Signals......Page 349 Listen for Django Model Signals......Page 350 Emit Custom Signals in Django Model Signals......Page 353 Django Models Inside Apps in the Models Folder......Page 354 Django Models Inside Apps in Custom Folders......Page 355 Django Models and Multiple Databases......Page 356 Multiple Database Routers: DATABASE_ROUTERS setting......Page 357 Create a Single Record with save() or create()......Page 361 Read a Single Record with get() or get_or_create()......Page 363 Update a Single Record with save(), update(), update_or_create(), or refresh_from_db()......Page 365 Delete a Single Record with delete()......Page 367 CRUD Multiple Records in Django Models......Page 368 Create Multiple Records with bulk_create()......Page 369 Read Multiple Records with all(), filter(), exclude(), or in_bulk()......Page 371 Understanding a QuerySet: Lazy Evaluation and Caching......Page 373 Read Performance Methods: defer(), only(), values(), values_list(), iterator(), exists(), and none()......Page 376 Update Multiple Records with update() or select_for_update()......Page 379 One to Many CRUD Operations......Page 381 Many to Many CRUD Operations......Page 385 One to One CRUD Operations......Page 387 Read Performance Relationship Methods: select_related() and prefetch_related()......Page 388 WHERE Queries: Django Field Lookups......Page 390 =/EQUAL and !=/NOT EQUAL queries: exact, iexact......Page 391 OR queries: Q() objects......Page 392 IN queries: in......Page 393 LIKE and ILIKE queries: contains, icontains, startswith, istartswith, endswith, iendswith......Page 394 Date and time queries: Range, date, year, month, day, week, week_day, time, hour, minute, second......Page 395 DISTINCT Queries......Page 397 Dates and times queries: dates() and datetimes()......Page 398 ORDER Queries: order_by() and reverse()......Page 399 LIMIT and OFFSET queries: Python slice syntax......Page 400 QuerySet merger: Pipe and itertools.chain......Page 401 UNION queries: union()......Page 402 EXCEPT queries: difference()......Page 403 COUNT queries: count() method and Count() class......Page 404 MAX, MIN, SUM, AVG, VARIANCE and STDDEV queries: Max(), Min(), Sum(), Avg(), Variance(), and StdDev() classes......Page 406 SQL expression queries: F expressions......Page 407 SQL function queries: Func expressions and Django database functions......Page 409 SQL subqueries: Subquery expressions......Page 410 Model Queries with Raw (Open-Ended) SQL......Page 412 SQL Queries with a Model Manager’s raw() Method......Page 413 SQL Queries with Python’s DB API......Page 415 Model Managers......Page 416 Custom and Multiple Model Managers......Page 417 Custom Model Managers and QuerySet Classes with Methods......Page 418 Custom Reverse Model Managers for Related Models......Page 421 Django Model Form Structure and Workflow......Page 422 Create Django Model Forms......Page 423 Model Form Required Options: Model and Fields or Exclude......Page 424 Model Form Default Field Mapping......Page 425 Model Form New and Custom Fields: Widgets, Labels, help_texts, error_messages, field_classes, and localize_fields......Page 427 ModelChoiceField and ModelMultipleChoiceField Form Field Options: queryset, empty_label, to_field_name, and label_from_instance......Page 429 Model Form Initialization: Initial and Instance......Page 432 Model Form Validation......Page 433 Model Formset Factory......Page 435 Class-Based Views with Models......Page 436 Create Model Records with the Class-Based View CreateView......Page 437 Basic CreateView options: Model, form_class, and success_url fields......Page 439 Customize template name, MIME type and context: template_name and content_type fields and get_context_data( ) method......Page 440 Customize form initialization and validation: Initial field, get_initial( ), get_form( ), form_valid( ), and form_invalid( ) methods......Page 441 Customize view method workflow: get() and post() methods......Page 443 Read Model Records with the Class-Based Views ListView and DetailView......Page 445 ListView Fields and Methods......Page 447 Customize record list: Queryset and ordering fields and pagination behavior......Page 448 Basic DetailView options: Model field and url with pk parameter......Page 450 Customize url and query parameters: pk_url_kwarg, slug_field and slug_url_kwarg......Page 451 Update Model Records with the Class-Based View UpateView......Page 452 Basic UpdateView options: Model, form_class and success_url fields, and url with pk parameter......Page 454 Delete Records with the Class-Bases View DeleteView......Page 455 Basic DeleteView options: Model and success_url fields and url with pk parameter......Page 456 Class-Based Views with Mixins......Page 457 User Types, Subtypes, Groups, and Permissions......Page 459 Create Users......Page 460 Manage Users......Page 463 Create and Manage Groups......Page 468 Permission Types......Page 470 Model Permissions: Add, Change, Delete, and Custom......Page 471 Model Meta permission options: default_permissions and permissions......Page 472 View Method Permission Checks......Page 473 URL Permission Checks......Page 476 Template Permission Checks......Page 477 Class-Based View Permission Checks......Page 478 User Authentication and Auto-Management......Page 480 Login and Logout Workflow......Page 481 Password Reset Workflow......Page 482 User Signup Workflow......Page 483 Custom User Model Fields......Page 485 Custom Authentication Back Ends......Page 487 Install and Set Up django-allauth......Page 489 First Log In and Log Out with Superuser in Django allauth......Page 491 Password Reset and Change with Django allauth......Page 493 Add and Change User Email with Django allauth......Page 494 Models and Database Tables Behind Django allauth......Page 495 Set Up Django allauth for Different Social Providers......Page 496 Set Up Facebook with Django allauth......Page 498 Set Up Google with Django allauth......Page 504 Set Up Twitter with Django allauth......Page 509 Set Up Django Models in the Django admin......Page 513 Django admin Read Record Options......Page 514 Record Display: list_display, format_html, empty_value_display......Page 516 Record Order: admin_order_field and ordering......Page 520 Record Links and Inline Edit: list_display_links and list_editable......Page 521 Record Pagination: list_per_page, list_max_show_all, paginator......Page 524 Record Search: search_fields, list_filter, show_full_result_count, preserve_filters......Page 525 Record Dates: date_hierarchy......Page 530 Record Relationships......Page 532 Display: list_display (continued)......Page 533 Order: admin_order_field (continued)......Page 534 Search: search_fields and list_filter (continued), admin.RelatedOnly FieldListFilter, list_select_related......Page 535 Django admin Create, Update, Delete Record Options......Page 537 Record Forms: fields, readonly_fields, exclude, fieldsets, formfield_overrides, form, prepopulated_fields......Page 538 Actions, Links, and Positions: save_on_top, save_as(Clone records), save_as_continue and view_on_site......Page 545 Relationships: filter_horizontal, filter_vertical, radio_fields, raw_id_fields, inlines......Page 547 Django admin Custom Global Values for Default Templates......Page 554 Django admin Custom Page Layout with Custom Templates......Page 556 Django admin Custom Static Resources......Page 558 Django admin Custom Data and Behaviors with admin Class Fields and Methods......Page 559 Django admin CRUD Permissions......Page 561 Multiple Django admin Sites......Page 563 REST Services in Django......Page 566 Standard View Method Designed as REST Service......Page 567 Django Tastypie Framework4......Page 571 Serializers and Views......Page 572 Class-Based Views......Page 575 Mixins and Generic Class-Based Views......Page 576 View Sets and Routers......Page 577 Set Up REST Framework Services Permissions......Page 579 Set Up REST Framework Login Page......Page 582 Strings, Unicode, and Other Annoying Text Behaviors......Page 584 Methods Arguments: Default, optional, *args, and **kwargs......Page 588 Classes and Subclasses......Page 591 Loops, Iterators, and Generators......Page 593 List Comprehensions, Generator Expressions, Maps, and Filters......Page 598 Lambda Keyword for Anonymous Methods......Page 600 Index......Page 601 Discover the Django web application framework and get started building Python-based web applications. This book takes you from the basics of Django all the way through to cutting-edge topics such as creating RESTful applications. Beginning Django also covers ancillary, but essential, development topics, including configuration settings, static resource management, logging, debugging, and email. Along with material on data access with SQL queries, you?ll have all you need to get up and running with Django 1.11 LTS, which is compatible with Python 2 and Python 3. Once you?ve built your web application, you?ll need to be the admin, so the next part of the book covers how to enforce permission management with users and groups. This technique allows you to restrict access to URLs and content, giving you total control of your data. In addition, you?ll work with and customize the Django admin site, which provides access to a Django project?s data. After reading and using this book, you?ll be able to build a Django application top to bottom and be ready to move on to more advanced or complex Django application development. You will: Get started with the Django framework Use Django views, class-based views, URLs, middleware, forms, templates, and Jinja templates Take advantage of Django models, including model relationships, migrations, queries, and forms Leverage the Django admin site to get access to the database used by a Django project Deploy Django REST services to serve as the data backbone for mobile, IoT, and SaaS systems
دانلود کتاب شروع با جنگو: توسعه و استقرار برنامههای وب با پایتون