Rubio | Beginning Django | E-Book | www.sack.de
E-Book

E-Book, Englisch, 609 Seiten

Rubio Beginning Django

Web Application Development and Deployment with Python
1. ed
ISBN: 978-1-4842-2787-9
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark

Web Application Development and Deployment with Python

E-Book, Englisch, 609 Seiten

ISBN: 978-1-4842-2787-9
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark



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 LearnGet 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 systemsWho This Book Is For 

Python developers new to the Django web application development framework and web developers new to Python and Django.

Daniel Rubio is an independent consultant with over 10 years of experience in enterprise and web-based software. More recently, Daniel is founder and technical lead at MashupSoft.com.  He has co-authored the best selling Spring Recipes as well as other books for Apress Media, LLC.  Daniel's expertise lies in Java, Spring, Python, Django, JavaScript/CSS and HTML.  

Rubio Beginning Django jetzt bestellen!

Autoren/Hrsg.


Weitere Infos & Material


1;Contents at a Glance;5
2;Contents;6
3;About the Author;20
4;About the Technical Reviewer;21
5;Acknowledgments;22
6;Introduction;23
7;Chapter 1: Introduction to the Django Framework;24
7.1;Django Framework Design Principles;25
7.1.1;Don’t Repeat Yourself (DRY) Principle;25
7.1.2;Explicit Is Better Than Implicit;27
7.1.3;Loosely Coupled Architecture;28
7.2;Install Django;28
7.2.1;Install Python (Prerequisite);29
7.2.2;Update or Install pip Package Manager (Prerequisite);30
7.2.3;Install virtualenv (Optional Prerequisite);31
7.2.4;Install Django;34
7.2.5;Install Django from Git;34
7.3;Start a Django Project;36
7.4;Set Up a Database for a Django Project;38
7.4.1;Install Python Database Packages;41
7.4.2;Test Django Database Connection and Build Django Base Tables;41
7.5;Set Up Content: Understand Urls, Templates, and Apps;42
7.5.1;Create and Configure Django Urls;43
7.5.2;Create and Configure Django Templates;44
7.5.3;Create and Configure Django Apps;45
7.6;Set Up the Django admin Site;48
7.6.1;Configure and Install the Django admin site App;48
7.6.2;Configure and Install the Django admin site docs App;51
8;Chapter 2: Django Urls and Views;53
8.1;Url Regular Expressions;53
8.1.1;Precedence Rule: Granular Urls First, Broad Urls Last;53
8.1.2;Exact Url Patterns: Forgoing Broad Matching;54
8.1.3;Common Url Patterns;55
8.2;Url Parameters, Extra Options, and Query Strings;57
8.3;Url Consolidation and Modularization;60
8.4;Url Naming and Namespaces;62
8.5;View Method Requests;69
8.6;View Method Responses;71
8.6.1;Response Options for HTTP Status and Content-Type Headers;72
8.6.2;Built-In Response Shortcuts and Templates for Common HTTP Status: 404 (Not Found), 500 (Internal Server Error), 400 (Bad Request), and 403 (Forbidden);73
8.6.3;Built-In Response Shortcuts for Inline and Streamed Content;77
8.7;View Method Middleware;79
8.7.1;Built-In Middleware Classes;79
8.7.2;Middleware Structure and Execution Process;82
8.8;Middleware Flash Messages in View Methods;86
8.8.1;Add Flash Messages;87
8.8.2;Access Flash Messages;89
8.9;Class-Based Views;90
8.9.1;Built-In Class-Based Views;91
8.9.2;Class-Based View Structure and Execution;91
9;Chapter 3: Django Templates;95
9.1;Django Template Syntax;95
9.1.1;Auto-Escaping: HTML and Erring on the Safe Side;96
9.2;Django Template Configuration;97
9.2.1;Template Search Paths;98
9.2.2;Invalid Template Variables;100
9.2.3;Debug Output;102
9.2.4;Auto-Escape;103
9.2.5;File charset;104
9.2.6;Automatic Access to Custom Template tag/filter Modules;105
9.2.7;Template Loaders;106
9.3;Create Reusable Templates;107
9.4;Built-In Context Processors;109
9.4.1;Django debug context processor (django.template.context_processors.debug);110
9.4.2;Django request context processor (django.template.context_processors.request);110
9.4.3;Django auth context processor (django.contrib.auth.context_processors.auth);110
9.4.4;Django messages context processor (django.contrib.messages.context_processors.messages);111
9.4.5;Other Built-In Django Context Processors: i18n, media, static, tz, and CSRF context Processors;111
9.4.5.1;Django i18n context processor (django.template.context_processors.i18n);111
9.4.5.2;Django media context processor (django.template.context_processors.media);111
9.4.5.3;Django static context processor (django.template.context_processors.static);111
9.4.5.4;Django tz context processor (django.template.context_processors.tz);112
9.4.5.5;Django CSRF context Processor (django.template.context_processors.csrf);112
9.5;Custom Context Processors;112
9.6;Built-In Django Filters;113
9.6.1;Dates;113
9.6.2;Strings, Lists, and Numbers;116
9.6.3;Numbers;117
9.6.4;Strings;118
9.6.5;Lists and Dictionaries;120
9.6.6;Spacing and Special Characters;121
9.6.7;Development and Testing;122
9.6.8;Urls;123
9.7;Built-In Django Tags;123
9.7.1;Dates;124
9.7.2;Forms;124
9.7.3;Comparison Operations;124
9.7.4;Loops;126
9.7.5;Python and Filter Operations;129
9.7.6;Spacing and Special Characters;130
9.7.7;Template Structures;131
9.7.8;Development and Testing;132
9.7.9;Urls;132
9.8;Custom Filters;132
9.8.1;Structure;132
9.8.2;Options: Naming, HTML, and What Comes In and Out;134
9.8.3;Installation and Access;136
10;Chapter 4: Jinja Templates in Django;138
10.1;Jinja Advantages and Disadvantages;138
10.2;Transition to Jinja Templates from Django Templates;139
10.2.1;What Works the Same Way in Jinja and Django Templates;139
10.2.1.1;Variables and blocks;140
10.2.1.2;Conditionals and loops;140
10.2.1.3;Comments;140
10.2.1.4;Spacing and special characters;140
10.2.2;What Works Differently in Jinja Templates Compared to Django Templates;140
10.2.2.1;Filters;140
10.2.2.2;Context processors;141
10.2.2.3;No date elements like the {% now %} tag and filters like time and timesince;141
10.2.2.4;{% comment %} tag not supported;141
10.2.2.5;{% load %} tag not supported;141
10.2.2.6;Use {{super()}} instead of {{block.super}};141
10.2.2.7;{% csrf_token %} tag not supported, instead use csrf_input or csrf_token variables;141
10.2.2.8;{% for %} loop variables;141
10.2.2.9;{% empty %} tag not supported in loops, use the {% else %} tag;142
10.2.2.10;{% groupby %} tag not supported, use the groupby filter;142
10.2.2.11;{% cycle %} tag not supported, use the cycler function or the loop.cycle variable in {% for %} loops;142
10.2.2.12;{% lorem %} tag not supported, use the lipsum Function;142
10.2.2.13;Other miscellaneous tags like {% static %}, {% trans %}, {% blocktrans %}, and {% url %} not supported;142
10.2.3;New Concepts and Features in Jinja Templates vs. Django Templates;142
10.2.3.1;More useful built-in filters, tests, and more resemblance to a Python environment;142
10.2.3.2;Global functions;143
10.2.3.3;Flexible tag nesting, conditionals, and references;143
10.2.3.4;Macros;143
10.2.3.5;Flexible variable assignment in templates with less restrictive scope;143
10.2.3.6;Line statements;143
10.3;Jinja Template Configuration in Django;144
10.3.1;Template Search Paths;144
10.3.2;Auto-Escaping Behavior;146
10.3.3;Auto-Reload Template Behavior and Caching;147
10.3.4;Invalid Template Variables;148
10.3.5;Template Loaders;149
10.4;Create Reusable Jinja Templates;149
10.5;Jinja Globals: Access Data on All Jinja Templates, Like Django Context Processors;155
10.6;Jinja Built-In Statements/Tags and Functions (Like Django Template Tags);156
10.6.1;Comparison Operations;157
10.6.2;Loops;158
10.6.3;Python and Filter Operations;162
10.6.4;Spacing and Special Characters;163
10.6.5;Template Structures;166
10.7;Jinja Built-In Filters and Tests (Like Django Filters);167
10.7.1;Strings, Lists, Dictionaries, Numbers, and Objects;167
10.7.2;Strings and Lists;168
10.7.3;Dictionaries and Objects;170
10.7.4;Strings;172
10.7.5;Numbers;172
10.7.6;Spacing and Special Characters;173
10.7.7;Development and Testing;176
10.7.8;Urls;176
10.8;Custom Filters and Tests in Jinja;176
10.8.1;Structure;176
10.8.2;Installation and Access;177
10.9;Jinja Extensions;179
10.9.1;Enable Jinja Extensions;180
10.9.2;Create Jinja Extensions;180
10.10;Jinja Policies;182
11;Chapter 5: Django Application Management;183
11.1;Django settings.py for the Real World;183
11.1.1;Switch DEBUG to False;183
11.1.2;Define ALLOWED_HOSTS;184
11.1.3;Be Careful with the SECRET_KEY Value;185
11.1.4;Define Administrators for ADMINS and MANAGERS;185
11.1.5;Use Dynamic Absolute Paths;186
11.1.6;Use Multiple Environments or Configuration Files for Django;188
11.1.6.1;Option 1) Multiple environments in the same settings.py file with a control variable;188
11.1.6.2;Option 2) Multiple environment files using configparser;190
11.1.6.3;Option 3) Multiple settings.py files with different names for each environment;192
11.2;Set Up Static Web Page Resources - Images, CSS, JavaScript;193
11.2.1;Set Up Static Resources in a Development Environment (DEBUG=False);193
11.2.2;Access Static Resources in Django Templates;196
11.2.3;Access Static Resources in Jinja Templates;198
11.2.4;Set Up Static Resources in a Production Environment (DEBUG=True);198
11.3;Django Logging;199
11.3.1;Python Core Logging Concepts;200
11.3.2;Django Default Logging;200
11.3.3;Create Log Messages;203
11.3.4;Custom Logging;205
11.3.4.1;Disable default Django logging configuration;206
11.3.4.2;Logging formatters: Message output;207
11.3.4.3;Logging handlers: Locations, classes, filters, and logging thresholds;208
11.3.4.4;Logging loggers: Python packages to use logging;209
11.3.4.5;Disable email to ADMINS on errors;209
11.3.5;Logging with Sentry;210
11.3.5.1;Set up Sentry the application;210
11.3.5.2;Set up a Django application to use Sentry;212
11.4;Django Email Service;213
11.4.1;Set Up a Default Connection to an Email Server;213
11.4.2;Set Up a Default Connection to Third-Party Email Providers;214
11.4.2.1;Email with Google Gmail/Google Apps;215
11.4.2.2;Email with Amazon Simple Email Service (SES);216
11.4.2.3;Email with SparkPost;216
11.4.3;Built-In Helpers to Send Email;217
11.4.4;Custom Email: Attachments, Headers, CC, BCC, and More with EmailMessage;219
11.5;Debug Django Applications;223
11.5.1;Django Shell: Python manage.py Shell;224
11.5.2;Django Debug Toolbar;224
11.5.3;Django pdb;226
11.5.4;Django Extensions;228
11.6;Django Management Commands;231
11.6.1;Custom Management Command Structure;232
11.6.2;Custom Management Command Installation;234
11.6.3;Management Command Automation;235
12;Chapter 6: Django Forms;237
12.1;Django Form Structure and Workflow;237
12.1.1;Functional Web Form Syntax for Django Forms;239
12.1.2;Django View Method to Process Form (POST Handling);240
12.1.3;CSRF: What Is It and How Does It Work with Django?;242
12.2;Django Form Processing: Initialization, Field Access, Validation, and Error Handling;244
12.2.1;Initialize Forms: Initial for Fields and Forms, __init__ method, label_suffix, auto_id, field_order, and use_required_attribute;245
12.2.2;Accessing Form Values: request.POST and cleaned_data;249
12.2.3;Validating Form Values: is_valid(), validators, clean_(), and clean();250
12.2.4;Error Form Values: Errors;254
12.3;Django Form Field Types: Widgets, Options, and Validations;255
12.3.1;The Relationship between Widgets and Form Fields;265
12.3.2;Empty, Default, and Predetermined Values: Required, Initial, and Choices;266
12.3.3;Limiting Text Values: max_length, min_length, strip, and Validators;266
12.3.4;Limiting Number Values: max_value, min_value, max_digits, decimal_places, and Validators;267
12.3.5;Error Messages: error_messages;267
12.3.6;Field Layout Values: label, label_suffix, help_text;268
12.4;Set Up the Layout for Django Forms in Templates;268
12.4.1;Output Form Fields: form.as_table, form.as_p, form.as_ul, and Granularly by Field;269
12.4.2;Output Field Order: field_order and order_fields;272
12.4.3;Output CSS Classes, Styles, and Field Attributes: error_css_class, required_css_class, Widget, Customization, and Various Form Field Options;272
12.4.4;Output Form Field Errors: form..errors, form.errors, form.non_field_errors;274
12.5;Django Custom Form Fields and Widgets;275
12.5.1;Create Custom Form Fields;276
12.5.2;Customize Built-In Widgets;277
12.5.3;Create Custom Form Widgets;278
12.5.4;Custom Form Widget Configuration Options;280
12.6;Django Advanced Form Processing: Partial Forms, AJAX, and Files;281
12.6.1;Partial Forms;281
12.6.2;AJAX Form Submission;283
12.6.3;Files in Forms;285
12.7;Django Formsets;288
12.7.1;Formset Factory;290
12.7.2;Formset Management Form and Formset Processing;290
12.7.3;Formset Custom Validation and Formset Errors;292
13;Chapter 7: Django Models;295
13.1;Django Models and the Migrations Workflow;295
13.1.1;Create Django Models;296
13.1.2;Migrations and the Django Model Workflow;297
13.2;Django Model Data Types;300
13.2.1;Limiting Values: max_length, min_value, max_value, max_digits, and decimal_places;307
13.2.2;Empty, Null and Not Null Values: Blank and Null;308
13.2.3;Predetermined Values: default, auto_now, auto_now_add, and choices;310
13.2.4;Unique values: unique, unique_for_date, unique_for_month and unique_for_year;313
13.2.5;Form Values: Editable, help_text, verbose_name, and error_messages;313
13.2.6;Database Definition Language (DDL) Values: db_column, db_index, db_tablespace, primary_key;314
13.2.7;Built-In and Custom Validators: Validators;315
13.3;Django Model Default and Custom Behaviors;316
13.3.1;Model Methods;316
13.3.1.1;save() method;316
13.3.1.2;delete() method;319
13.3.1.3;Validation methods: clean_fields(), clean(), validate_unique() and full_clean();319
13.3.1.4;Data loading methods: Refresh_from_db(), from_db(), and get_deferred_fields() methods;323
13.3.1.5;Custom methods;324
13.3.2;Model Manager Field: Objects;324
13.3.3;Model Meta Class and Options;325
13.3.3.1;Database Definition Language (DDL) table options: db_table, db_tablespace, managed, required_db_vendor, required_db_features and unique_together;325
13.3.3.2;Database Definition Language (DDL) index options: Indexes and index_together;326
13.3.3.3;Naming convention options: verbose_name, verbose_name_plural, label, label_lower, and app_label;327
13.3.3.4;Inheritance Meta options: Abstract and proxy;328
13.3.3.5;Query Meta options: Ordering, order_with_respect_to, get_latest_by,   default_manager_name, base_manager_name, default_related_name, and select_on_save;329
13.3.3.6;Permission Meta options: default_permissions and permissions;330
13.4;Relationships in Django Models;330
13.4.1;One to Many Relationships in Django Models;331
13.4.2;Many to Many Relationships in Django Models;331
13.4.3;One to One Relationships in Django Models;332
13.4.4;Options for Relationship Model Data Types;333
13.4.4.1;Data integrity options: on_delete;333
13.4.4.2;Reference options: Self, literal strings, and parent_link;334
13.4.4.3;Reverse relationships: related_name, related_query_name, and symmetrical;334
13.4.4.4;Database options: to_field, db_constraint, swappable, through, through_fields, and db_table;336
13.4.4.5;Form values: limit_choices_to;336
13.5;Django Model Transactions;337
13.5.1;Transaction per Request: ATOMIC_REQUESTS and Decorators;337
13.5.2;Context Manager and Callbacks: atomic() and on_commit();338
13.6;Django Model Migrations;339
13.6.1;Migration File Creation;339
13.6.2;Migration File Renaming;340
13.6.3;Migration File Squashing;341
13.6.4;Migration File Structure;342
13.6.5;Migration File Rollback;343
13.7;Django Model Database Tasks;343
13.7.1;Backup Data: Fixtures, dumpdata, loaddata, and inspectdb;344
13.7.2;Delete Data: Flush, sqlflush, and sqlsequencereset;344
13.7.3;Interact with Data: dbshell;345
13.8;Django Model Initial Data Setup;345
13.8.1;Hard-code predefined records in Python migration file;345
13.8.2;SQL script with SQL statements;346
13.8.3;Django fixture file;348
13.9;Django Model Signals;349
13.9.1;Built-In Django Model Signals;350
13.9.2;Listen for Django Model Signals;350
13.9.3;Emit Custom Signals in Django Model Signals;353
13.10;Django Models Outside of models.py;354
13.10.1;Django Models Inside Apps in the Models Folder;354
13.10.2;Django Models Inside Apps in Custom Folders;355
13.10.3;Django Models Outside Apps and Model Assignment to Other Apps;356
13.11;Django Models and Multiple Databases;356
13.11.1;Multiple Databases for Django Models: using;357
13.11.2;Multiple Databases for Django Tools: --database;357
13.11.3;Multiple Database Routers: DATABASE_ROUTERS setting;357
14;Chapter 8: Django Model Queries and Managers;361
14.1;CRUD Single Records in Django Models;361
14.1.1;Create a Single Record with save() or create();361
14.1.2;Read a Single Record with get() or get_or_create();363
14.1.3;Update a Single Record with save(), update(), update_or_create(), or refresh_from_db();365
14.1.4;Delete a Single Record with delete();367
14.2;CRUD Multiple Records in Django Models;368
14.2.1;Create Multiple Records with bulk_create();369
14.2.2;Read Multiple Records with all(), filter(), exclude(), or in_bulk();371
14.2.3;Understanding a QuerySet: Lazy Evaluation and Caching;373
14.2.4;Read Performance Methods: defer(), only(), values(), values_list(), iterator(), exists(), and none();376
14.2.5;Update Multiple Records with update() or select_for_update();379
14.2.6;Delete Multiple Records with delete();381
14.3;CRUD Relationship Records Across Django Models;381
14.3.1;One to Many CRUD Operations;381
14.3.2;Many to Many CRUD Operations;385
14.3.3;One to One CRUD Operations;387
14.3.4;Read Performance Relationship Methods: select_related() and prefetch_related();388
14.4;Model Queries by SQL Keyword;390
14.4.1;WHERE Queries: Django Field Lookups;390
14.4.1.1;=/EQUAL and !=/NOT EQUAL queries: exact, iexact;391
14.4.1.2;AND queries;392
14.4.1.3;OR queries: Q() objects;392
14.4.1.4;IS and IS NOT queries: isnull;393
14.4.1.5;IN queries: in;393
14.4.1.6;LIKE and ILIKE queries: contains, icontains, startswith, istartswith, endswith, iendswith;394
14.4.1.7;REGEXP queries: regex, iregex;395
14.4.1.8;>/GREATER THAN and



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.