Suchen und Finden
Contents at a Glance
4
Contents
6
About the Authors
26
About the Technical Reviewer
27
Acknowledgments
28
Introduction
29
Getting Started
31
Introduction to Django
32
What Is a Web Framework?
32
The MVC Design Pattern
34
Django’s History
35
How to Read This Book
36
What’s Next?
38
Getting Started
39
Installing Python
39
Installing Django
39
Setting Up a Database
41
Starting a Project
42
What’s Next?
44
The Basics of Dynamic Web Pages
45
Your First View: Dynamic Content
45
Mapping URLs to Views
46
How Django Processes a Request
49
URLconfs and Loose Coupling
51
404 Errors
51
Your Second View: Dynamic URLs
52
Django’s Pretty Error Pages
56
What’s Next?
58
The Django Template System
59
Template System Basics
59
Using the Template System
61
Basic Template Tags and Filters
68
Philosophies and Limitations
75
Using Templates in Views
76
Template Loading
77
Template Inheritance
82
What’s Next?
86
Interacting with a Database: Models
87
The “ Dumb” Way to Do Database Queries in Views
87
The MTV Development Pattern
88
Configuring the Database
90
Your First App
92
Defining Models in Python
93
Your First Model
94
Installing the Model
96
Basic Data Access
99
Adding Model String Representations
100
Inserting and Updating Data
101
Selecting Objects
102
Deleting Objects
106
Making Changes to a Database Schema
107
What’s Next?
110
The Django Administration Site
111
Activating the Admin Interface
111
Using the Admin Interface
113
Customizing the Admin Interface
119
Customizing the Admin Interface’s Look and Feel
121
Customizing the Admin Index Page
121
When and Why to Use the Admin Interface
122
What’s Next?
122
Form Processing
123
Search
123
The “ Perfect Form”
126
Creating a Feedback Form
126
Processing the Submission
129
Custom Validation Rules
131
A Custom Look and Feel
131
Creating Forms from Models
133
What’s Next?
134
Advanced Views and URLconfs
135
URLconf Tricks
135
Including Other URLconfs
148
What’s Next?
150
Django’s Subframeworks
151
Generic Views
152
Using Generic Views
152
Generic Views of Objects
154
Extending Generic Views
155
What’s Next?
160
Extending the Template Engine
161
Template Language Review
161
RequestContext and Context Processors
162
Inside Template Loading
167
Extending the Template System
168
Writing Custom Template Loaders
178
Using the Built- in Template Reference
180
Configuring the Template System in Standalone Mode
180
What’s Next?
181
Generating Non-HTML Content
182
The Basics: Views and MIME Types
182
Producing CSV
183
Generating PDFs
184
Other Possibilities
187
The Syndication Feed Framework
187
The Sitemap Framework
194
What’s Next?
199
Sessions, Users, and Registration
200
Cookies
200
Django’s Session Framework
203
Users and Authentication
208
The Other Bits: Permissions, Groups, Messages, and Profiles
218
What’s Next?
221
Caching
222
Setting Up the Cache
223
The Per- Site Cache
226
The Per- View Cache
227
The Low- Level Cache API
228
Upstream Caches
229
Other Optimizations
233
Order of MIDDLEWARE_ CLASSES
233
What’s Next?
233
Other Contributed Subframeworks
234
The Django Standard Library
234
Sites
235
Flatpages
241
Redirects
244
CSRF Protection
246
Form Tools
248
Humanizing Data
250
Markup Filters
251
What’s Next?
251
Middleware
252
What’s Middleware?
252
Middleware Installation
253
Middleware Methods
254
Built- in Middleware
255
What’s Next?
258
Integrating with Legacy Databases and Applications
259
Integrating with a Legacy Database
259
Integrating with an Authentication System
261
Integrating with Legacy Web Applications
263
What’s Next?
264
Extending Django’s Admin Interface
265
The Zen of Admin
266
Customizing Admin Templates
267
Creating Custom Admin Views
270
Overriding Built- in Views
273
What’s Next?
273
Internationalization
274
Specifying Translation Strings in Python Code
275
Specifying Translation Strings in Template Code
277
Creating Language Files
279
How Django Discovers Language Preference
281
The set_ language Redirect View
283
Using Translations in Your Own Projects
284
Translations and JavaScript
285
Notes for Users Familiar with gettext
287
What’s Next?
287
Security
288
The Theme of Web Security
288
SQL Injection
289
Cross- Site Scripting
290
Cross- Site Request Forgery
292
Session Forging/ Hijacking
292
Email Header Injection
294
Directory Traversal
294
Exposed Error Messages
296
A Final Word on Security
296
What’s Next?
296
Deploying Django
297
Shared Nothing
298
A Note on Personal Preferences
300
Using Django with Apache and mod_ python
300
Using Django with FastCGI
304
Scaling
310
Performance Tuning
315
What’s Next?
316
Appendixes
317
Case Studies
318
Cast of Characters
318
Why Django?
320
Getting Started
320
Porting Existing Code
321
How Did It Go?
321
Team Structure
323
Deployment
324
Model Definition Reference
325
Fields
325
Universal Field Options
330
Relationships
334
Model Metadata Options
337
Managers
340
Model Methods
343
Admin Options
346
Database API Reference
353
Creating Objects
354
Saving Changes to Objects
355
Retrieving Objects
356
Caching and QuerySets
357
Filtering Objects
357
Field Lookups
366
Complex Lookups with Q Objects
370
Related Objects
371
Deleting Objects
375
Extra Instance Methods
376
Shortcuts
377
Falling Back to Raw SQL
378
Generic View Reference
379
Common Arguments to Generic Views
379
“ Simple” Generic Views
380
List/ Detail Generic Views
381
Date- Based Generic Views
385
Create/ Update/ Delete Generic Views
395
Settings
399
What’s a Settings File?
399
Designating the Settings: DJANGO_ SETTINGS_ MODULE
401
Using Settings Without Setting DJANGO_ SETTINGS_ MODULE
402
Available Settings
403
Built-in Template Tags and Filters
415
Built- in Tag Reference
415
Built- in Filter Reference
425
The django-admin Utility
435
Usage
435
Available Actions
436
Available Option
441
Request and Response Objects
444
HttpRequest
444
HttpResponse
448
Index
452
Alle Preise verstehen sich inklusive der gesetzlichen MwSt.