The Definitive Guide to Django (eBook)
447 Seiten
Apress (Verlag)
978-1-4302-0331-5 (ISBN)
Django, the Python-based Web development framework, is one of the hottest topics in Web development today. Its creator (and co-author of this book) Adrian Holovaty has built a compelling array of Web applications using Django, including http://chicagocrime.org. Django creator Adrian Holovaty and lead developer Jacob Kaplan-Moss have created this book as the definitive guide to the technology. Beginning with fundamentals such as installation and configuration, the book tackles sophisticated features of Django, such as outputting non-HTML content such as RSS feeds and PDFs, caching, and user management. Also includes a detailed reference to Django's many configuration options and commands.
Jacob Kaplan-Moss is one of the lead developers of Django. At his day job, he's the lead developer for the Lawrence Journal-World, a locally owned newspaper in Lawrence, Kansas, where Django was developed. At the Journal-World, Jacob hacks on a number of sites including lawrence.com, LJWorld.com, and KUsports.com, and he is continually embarrassed by the multitude of media awards those sites win. In his spare time what little of it there is he fancies himself a chef.
Django, the Python-based equivalent to the Ruby on Rails web development framework, is hottest topics in web development. In The Definitive Guide to Django: Web Development Done Right, Adrian Holovaty, one of Django's creators, and Django lead developer Jacob Kaplan-Moss show you how they use this framework to create award-winning web sites. Over the course of three parts, they guide you through the creation of a web application reminiscent of chicagocrime.org.The first part of the book introduces Django fundamentals like installation and configuration. You'll learn about creating the components that power a Django-driven web site. The second part delves into the more sophisticated features of Django, like outputting non HTML content (such as RSS feeds and PDFs), plus caching and user management. The third part serves as a detailed reference to Django's many configuration options and commands. The book even includes seven appendices for looking up configurations options and commands. In all, this book provides the ultimate tutorial and reference to the popular Django framework.
Jacob Kaplan-Moss is one of the lead developers of Django. At his day job, he's the lead developer for the Lawrence Journal-World, a locally owned newspaper in Lawrence, Kansas, where Django was developed. At the Journal-World, Jacob hacks on a number of sites including lawrence.com, LJWorld.com, and KUsports.com, and he is continually embarrassed by the multitude of media awards those sites win. In his spare time what little of it there is he fancies himself a chef.
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
Erscheint lt. Verlag | 8.3.2008 |
---|---|
Zusatzinfo | 447 p. |
Verlagsort | Berkeley |
Sprache | englisch |
Themenwelt | Mathematik / Informatik ► Informatik ► Software Entwicklung |
Informatik ► Web / Internet ► Web Design / Usability | |
Schlagworte | Databases • Development • Middleware • Tutorial • Uniform Resource Locator (URL) |
ISBN-10 | 1-4302-0331-5 / 1430203315 |
ISBN-13 | 978-1-4302-0331-5 / 9781430203315 |
Haben Sie eine Frage zum Produkt? |
Größe: 2,6 MB
DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasserzeichen und ist damit für Sie personalisiert. Bei einer missbräuchlichen Weitergabe des eBooks an Dritte ist eine Rückverfolgung an die Quelle möglich.
Dateiformat: PDF (Portable Document Format)
Mit einem festen Seitenlayout eignet sich die PDF besonders für Fachbücher mit Spalten, Tabellen und Abbildungen. Eine PDF kann auf fast allen Geräten angezeigt werden, ist aber für kleine Displays (Smartphone, eReader) nur eingeschränkt geeignet.
Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.
Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.
Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.
aus dem Bereich