| About the Authors | | xxvii | |
| About the Technical Reviewer | | xxviii | |
| Acknowledgments | | xxix | |
| Introduction | | xxxi | |
| |
| | 3 | |
| | 3 | |
| | 5 | |
| | 6 | |
| | 7 | |
| Required Programming Knowledge |
| | 8 | |
| Required Python Knowledge |
| | 8 | |
| | 8 | |
| | 9 | |
| | 9 | |
| | 11 | |
| | 11 | |
| | 11 | |
| Installing an Official Release |
| | 11 | |
| Installing Django from Subversion |
| | 12 | |
| | 13 | |
| Using Django with PostgreSQL |
| | 13 | |
| Using Django with SQLite 3 |
| | 14 | |
| | 14 | |
| Using Django Without a Database |
| | 14 | |
| | 14 | |
| | 15 | |
| | 16 | |
| The Basics of Dynamic Web Pages |
| | 17 | |
| Your First View: Dynamic Content |
| | 17 | |
| | 18 | |
| How Django Processes a Request |
| | 21 | |
| How Django Processes a Request: Complete Details |
| | 22 | |
| URLconfs and Loose Coupling |
| | 23 | |
| | 23 | |
| Your Second View: Dynamic URLs |
| | 24 | |
| | 25 | |
| | 25 | |
| Django's Pretty Error Pages |
| | 28 | |
| | 30 | |
| The Django Template System |
| | 31 | |
| | 31 | |
| Using the Template System |
| | 33 | |
| Creating Template Objects |
| | 33 | |
| | 34 | |
| Multiple Contexts, Same Template |
| | 36 | |
| | 37 | |
| Playing with Context Objects |
| | 40 | |
| Basic Template Tags and Filters |
| | 40 | |
| | 40 | |
| | 46 | |
| Philosophies and Limitations |
| | 47 | |
| | 48 | |
| | 49 | |
| | 52 | |
| | 53 | |
| Subdirectories in get_template() |
| | 53 | |
| | 54 | |
| | 54 | |
| | 58 | |
| Interacting with a Database: Models |
| | 59 | |
| The ``Dumb'' Way to Do Database Queries in Views |
| | 59 | |
| The MTV Development Pattern |
| | 60 | |
| | 62 | |
| | 64 | |
| Defining Models in Python |
| | 65 | |
| | 66 | |
| | 68 | |
| | 71 | |
| Adding Model String Representations |
| | 72 | |
| Inserting and Updating Data |
| | 73 | |
| | 74 | |
| | 75 | |
| Retrieving Single Objects |
| | 76 | |
| | 76 | |
| | 77 | |
| | 78 | |
| | 78 | |
| Making Changes to a Database Schema |
| | 79 | |
| | 79 | |
| | 81 | |
| Removing Many-to-Many Fields |
| | 82 | |
| | 82 | |
| | 82 | |
| The Django Administration Site |
| | 83 | |
| Activating the Admin Interface |
| | 83 | |
| Using the Admin Interface |
| | 85 | |
| Users, Groups, and Permissions |
| | 90 | |
| Customizing the Admin Interface |
| | 91 | |
| Customizing the Admin Interface's Look and Feel |
| | 93 | |
| Customizing the Admin Index Page |
| | 93 | |
| When and Why to Use the Admin Interface |
| | 94 | |
| | 94 | |
| | 95 | |
| | 95 | |
| | 98 | |
| | 98 | |
| Processing the Submission |
| | 101 | |
| | 103 | |
| | 103 | |
| Creating Forms from Models |
| | 105 | |
| | 106 | |
| Advanced Views and URLconfs |
| | 107 | |
| | 107 | |
| Streamlining Function Imports |
| | 107 | |
| Using Multiple View Prefixes |
| | 109 | |
| Special-Casing URLs in Debug Mode |
| | 109 | |
| | 110 | |
| Understanding the Matching/Grouping Algorithm |
| | 112 | |
| Passing Extra Options to View Functions |
| | 112 | |
| Using Default View Arguments |
| | 117 | |
| | 118 | |
| | 119 | |
| Determining What the URLconf Searches Against |
| | 119 | |
| | 120 | |
| How Captured Parameters Work with include() |
| | 121 | |
| How Extra URLconf Options Work with include() |
| | 121 | |
| | 122 | |
| PART 2 Django's Subframeworks |
| |
| | 125 | |
| | 125 | |
| | 127 | |
| | 128 | |
| Making ``Friendly'' Template Contexts |
| | 128 | |
| | 129 | |
| Viewing Subsets of Objects |
| | 130 | |
| Complex Filtering with Wrapper Functions |
| | 131 | |
| | 131 | |
| | 133 | |
| Extending the Template Engine |
| | 135 | |
| | 135 | |
| RequestContext and Context Processors |
| | 136 | |
| django.core.context_processors.auth |
| | 140 | |
| django.core.context_processors.debug |
| | 140 | |
| django.core.context_processors.i18n |
| | 140 | |
| django.core.context_processors.request |
| | 141 | |
| Guidelines for Writing Your Own Context Processors |
| | 141 | |
| | 141 | |
| Extending the Template System |
| | 142 | |
| Creating a Template Library |
| | 142 | |
| Writing Custom Template Filters |
| | 144 | |
| Writing Custom Template Tags |
| | 145 | |
| | 150 | |
| | 151 | |
| Writing Custom Template Loaders |
| | 152 | |
| Using the Built-in Template Reference |
| | 154 | |
| Configuring the Template System in Standalone Mode |
| | 154 | |
| | 155 | |
| Generating Non-HTML Content |
| | 157 | |
| The Basics: Views and MIME Types |
| | 157 | |
| | 158 | |
| | 159 | |
| | 160 | |
| | 160 | |
| | 161 | |
| | 162 | |
| The Syndication Feed Framework |
| | 162 | |
| | 163 | |
| | 164 | |
| | 165 | |
| Specifying the Type of Feed |
| | 167 | |
| | 167 | |
| | 168 | |
| | 168 | |
| Publishing Atom and RSS Feeds in Tandem |
| | 168 | |
| | 169 | |
| | 169 | |
| | 170 | |
| | 170 | |
| | 171 | |
| | 172 | |
| | 173 | |
| | 174 | |
| Sessions, Users, and Registration |
| | 175 | |
| | 175 | |
| Getting and Setting Cookies |
| | 176 | |
| The Mixed Blessing of Cookies |
| | 177 | |
| Django's Session Framework |
| | 178 | |
| | 178 | |
| | 179 | |
| | 180 | |
| Using Sessions Outside of Views |
| | 181 | |
| | 181 | |
| Browser-Length Sessions vs. Persistent Sessions |
| | 182 | |
| | 182 | |
| | 183 | |
| Enabling Authentication Support |
| | 184 | |
| | 184 | |
| | 186 | |
| Limiting Access to Logged-in Users |
| | 188 | |
| Limiting Access to Users Who Pass a Test |
| | 189 | |
| Managing Users, Permissions, and Groups |
| | 190 | |
| Using Authentication Data in Templates |
| | 193 | |
| The Other Bits: Permissions, Groups, Messages, and Profiles |
| | 193 | |
| | 193 | |
| | 194 | |
| | 195 | |
| | 196 | |
| | 196 | |
| | 197 | |
| | 198 | |
| | 198 | |
| | 199 | |
| | 199 | |
| | 200 | |
| Simple Caching (for Development) |
| | 200 | |
| Dummy Caching (for Development) |
| | 200 | |
| | 200 | |
| | 201 | |
| | 202 | |
| Specifying Per-View Cache in the URLconf |
| | 203 | |
| | 203 | |
| | 204 | |
| | 205 | |
| | 207 | |
| | 208 | |
| Order of Middleware_Classes |
| | 208 | |
| | 208 | |
| Other Contributed Subframeworks |
| | 209 | |
| The Django Standard Library |
| | 209 | |
| | 210 | |
| Scenario 1: Reusing Data on Multiple Sites |
| | 210 | |
| Scenario 2: Storing Your Site Name/Domain in One Place |
| | 211 | |
| How to Use the Sites Framework |
| | 211 | |
| The Sites Framework's Capabilities |
| | 212 | |
| | 215 | |
| How Django Uses the Sites Framework |
| | 216 | |
| | 216 | |
| | 217 | |
| Adding, Changing, and Deleting Flatpages |
| | 218 | |
| | 219 | |
| | 219 | |
| Using the Redirects Framework |
| | 220 | |
| Adding, Changing, and Deleting Redirects |
| | 220 | |
| | 221 | |
| | 221 | |
| A More Complex CSRF Example |
| | 221 | |
| | 222 | |
| | 223 | |
| django.contrib.formtools.preview |
| | 223 | |
| | 224 | |
| | 225 | |
| | 225 | |
| | 225 | |
| | 225 | |
| | 226 | |
| | 226 | |
| | 226 | |
| | 227 | |
| | 227 | |
| | 228 | |
| | 229 | |
| Initializer:___init___(self) |
| | 229 | |
| Request Preprocessor: process_request(self, request) |
| | 229 | |
| View Preprocessor: process_view(self, request, view, args, kwargs) |
| | 229 | |
| Response Postprocessor: process_response(self, request, response) |
| | 230 | |
| Exception Postprocessor: process_exception(self, request, exception) |
| | 230 | |
| | 230 | |
| Authentication Support Middleware |
| | 231 | |
| | 231 | |
| | 232 | |
| Conditional GET Middleware |
| | 232 | |
| Reverse Proxy Support (X-Forwarded-For Middleware) |
| | 232 | |
| Session Support Middleware |
| | 232 | |
| Sitewide Cache Middleware |
| | 233 | |
| | 233 | |
| | 233 | |
| | 233 | |
| Integrating with Legacy Databases and Applications |
| | 235 | |
| Integrating with a Legacy Database |
| | 235 | |
| | 235 | |
| Cleaning Up Generated Models |
| | 236 | |
| Integrating with an Authentication System |
| | 237 | |
| Specifying Authentication Back-Ends |
| | 237 | |
| Writing an Authentication Back-End |
| | 237 | |
| Integrating with Legacy Web Applications |
| | 239 | |
| | 240 | |
| Extending Django's Admin Interface |
| | 241 | |
| | 242 | |
| | 242 | |
| | 242 | |
| ``... structured content'' |
| | 243 | |
| | 243 | |
| Customizing Admin Templates |
| | 243 | |
| | 244 | |
| | 245 | |
| Creating Custom Admin Views |
| | 246 | |
| Overriding Built-in Views |
| | 249 | |
| | 249 | |
| | 251 | |
| Specifying Translation Strings in Python Code |
| | 252 | |
| Standard Translation Functions |
| | 252 | |
| | 253 | |
| | 253 | |
| | 254 | |
| Specifying Translation Strings in Template Code |
| | 254 | |
| | 256 | |
| | 256 | |
| | 258 | |
| How Django Discovers Language Preference |
| | 258 | |
| The set_language Redirect View |
| | 260 | |
| Using Translations in Your Own Projects |
| | 261 | |
| Translations and JavaScript |
| | 262 | |
| The javascript_catalog View |
| | 262 | |
| Using the JavaScript Translation Catalog |
| | 263 | |
| Creating JavaScript Translation Catalogs |
| | 263 | |
| Notes for Users Familiar with gettext |
| | 264 | |
| | 264 | |
| | 265 | |
| The Theme of Web Security |
| | 265 | |
| | 266 | |
| | 266 | |
| | 267 | |
| | 268 | |
| Cross-Site Request Forgery |
| | 269 | |
| Session Forging/Hijacking |
| | 269 | |
| | 270 | |
| | 271 | |
| | 271 | |
| | 271 | |
| | 272 | |
| | 273 | |
| | 273 | |
| | 273 | |
| | 273 | |
| | 275 | |
| | 276 | |
| A Note on Personal Preferences |
| | 278 | |
| Using Django with Apache and mod_python |
| | 278 | |
| | 279 | |
| Running Multiple Django Installations on the Same Apache Instance |
| | 280 | |
| Running a Development Server with mod_python |
| | 280 | |
| Serving Django and Media Files from the Same Apache Instance |
| | 281 | |
| | 281 | |
| Handling a Segmentation Fault |
| | 282 | |
| Using Django with FastCGI |
| | 282 | |
| | 282 | |
| Running Your FastCGI Server |
| | 283 | |
| Using Django with Apache and FastCGI |
| | 284 | |
| | 285 | |
| Running Django on a Shared-Hosting Provider with Apache |
| | 287 | |
| | 288 | |
| Running on a Single Server |
| | 288 | |
| Separating Out the Database Server |
| | 289 | |
| Running a Separate Media Server |
| | 289 | |
| Implementing Load Balancing and Redundancy |
| | 290 | |
| | 292 | |
| | 293 | |
| There's No Such Thing As Too Much RAM |
| | 293 | |
| | 293 | |
| | 294 | |
| | 294 | |
| | 294 | |
| | 294 | |
| |
| | 297 | |
| | 297 | |
| | 299 | |
| | 299 | |
| | 300 | |
| | 300 | |
| | 302 | |
| | 303 | |
| APPENDIX B Model Definition Reference |
| | 305 | |
| | 305 | |
| | 305 | |
| | 306 | |
| | 306 | |
| | 306 | |
| CommaSeparatedlntegerField |
| | 306 | |
| | 306 | |
| | 307 | |
| | 307 | |
| | 307 | |
| | 308 | |
| | 308 | |
| | 309 | |
| | 309 | |
| | 309 | |
| | 309 | |
| | 309 | |
| | 309 | |
| PositiveSmallIntegerField |
| | 309 | |
| | 309 | |
| | 310 | |
| | 310 | |
| | 310 | |
| | 310 | |
| | 310 | |
| | 310 | |
| | 310 | |
| | 310 | |
| | 311 | |
| | 311 | |
| | 312 | |
| | 312 | |
| | 312 | |
| | 312 | |
| | 312 | |
| | 312 | |
| | 312 | |
| | 313 | |
| | 313 | |
| | 313 | |
| | 313 | |
| | 313 | |
| | 314 | |
| Many-to-One Relationships |
| | 314 | |
| Many-to-Many Relationships |
| | 316 | |
| | 317 | |
| | 317 | |
| | 318 | |
| | 318 | |
| | 318 | |
| | 318 | |
| | 319 | |
| | 319 | |
| | 320 | |
| | 320 | |
| | 320 | |
| | 320 | |
| | 321 | |
| | 323 | |
| | 324 | |
| | 324 | |
| | 325 | |
| Overriding Default Model Methods |
| | 326 | |
| | 326 | |
| | 326 | |
| | 327 | |
| | 328 | |
| | 328 | |
| | 330 | |
| | 330 | |
| | 331 | |
| | 331 | |
| | 331 | |
| | 331 | |
| | 331 | |
| | 332 | |
| APPENDIX C Database API Reference |
| | 333 | |
| | 334 | |
| What Happens When You Save? |
| | 334 | |
| Autoincrementing Primary Keys |
| | 334 | |
| Saving Changes to Objects |
| | 335 | |
| | 336 | |
| | 337 | |
| | 337 | |
| | 338 | |
| | 339 | |
| Query Methods That Return New QuerySets |
| | 339 | |
| QuerySet Methods That Do Not Return QuerySets |
| | 343 | |
| | 346 | |
| | 346 | |
| | 347 | |
| | 347 | |
| | 347 | |
| | 348 | |
| | 348 | |
| | 348 | |
| | 348 | |
| | 348 | |
| | 348 | |
| | 349 | |
| | 349 | |
| | 349 | |
| | 349 | |
| Complex Lookups with Q Objects |
| | 350 | |
| | 351 | |
| Lookups That Span Relationships |
| | 351 | |
| Foreign Key Relationships |
| | 352 | |
| ``Reverse'' Foreign Key Relationships |
| | 352 | |
| Many-to-Many Relationships |
| | 354 | |
| Queries over Related Objects |
| | 355 | |
| | 355 | |
| | 356 | |
| | 356 | |
| get_next_by_FOO(**kwargs) and get_previous_by_FOO(**kwargs) |
| | 356 | |
| | 357 | |
| | 357 | |
| | 357 | |
| save_FOO_file(filename, raw_contents) |
| | 357 | |
| get_FOO_height() and get_FOO_width() |
| | 357 | |
| | 357 | |
| | 357 | |
| | 358 | |
| | 358 | |
| APPENDIX D Generic View Reference |
| | 359 | |
| Common Arguments to Generic Views |
| | 359 | |
| | 360 | |
| | 360 | |
| Redirecting to Another URL |
| | 360 | |
| List/Detail Generic Views |
| | 361 | |
| | 361 | |
| | 363 | |
| | 365 | |
| | 365 | |
| | 367 | |
| | 368 | |
| | 370 | |
| | 371 | |
| | 372 | |
| | 373 | |
| Create/Update/Delete Generic Views |
| | 375 | |
| | 375 | |
| | 377 | |
| | 378 | |
| | 379 | |
| | 379 | |
| | 380 | |
| Seeing Which Settings You've Changed |
| | 380 | |
| Using Settings in Python Code |
| | 380 | |
| Altering Settings at Runtime |
| | 380 | |
| | 381 | |
| Creating Your Own Settings |
| | 381 | |
| Designating the Settings: Django_Settings_Module |
| | 381 | |
| The django-admin.py Utility |
| | 381 | |
| On the Server (mod_python) |
| | 382 | |
| Using Settings Without Setting Django_Settings_Module |
| | 382 | |
| | 383 | |
| Either configure() or Django_Settings_Module Is Required |
| | 383 | |
| | 383 | |
| | 383 | |
| | 384 | |
| | 384 | |
| | 384 | |
| | 384 | |
| | 384 | |
| | 385 | |
| Cache_Middleware_Key_Prefix |
| | 385 | |
| | 385 | |
| | 385 | |
| | 385 | |
| | 385 | |
| | 385 | |
| | 386 | |
| | 386 | |
| | 386 | |
| | 386 | |
| | 386 | |
| | 386 | |
| | 387 | |
| | 387 | |
| | 387 | |
| | 387 | |
| | 387 | |
| | 387 | |
| | 387 | |
| | 388 | |
| | 388 | |
| | 388 | |
| | 388 | |
| | 388 | |
| | 388 | |
| | 388 | |
| | 389 | |
| | 389 | |
| | 389 | |
| | 389 | |
| | 390 | |
| | 390 | |
| | 390 | |
| | 390 | |
| | 390 | |
| | 390 | |
| | 391 | |
| | 391 | |
| | 391 | |
| | 391 | |
| | 391 | |
| | 391 | |
| | 391 | |
| | 392 | |
| Session_Expire_At_Browser_Close |
| | 392 | |
| Session_Save_Every_Request |
| | 392 | |
| | 392 | |
| Template_Context_Processors |
| | 392 | |
| | 392 | |
| | 393 | |
| | 393 | |
| Template_String_If-Invalid |
| | 393 | |
| | 393 | |
| | 393 | |
| | 393 | |
| | 393 | |
| | 394 | |
| | 394 | |
| | 394 | |
| | 394 | |
| APPENDIX F Built-in Template Tags and Filters |
| | 395 | |
| | 395 | |
| | 395 | |
| | 395 | |
| | 395 | |
| | 396 | |
| | 396 | |
| | 396 | |
| | 396 | |
| | 397 | |
| | 397 | |
| | 399 | |
| | 399 | |
| | 399 | |
| | 400 | |
| | 400 | |
| | 400 | |
| | 402 | |
| | 403 | |
| | 403 | |
| | 403 | |
| | 404 | |
| | 404 | |
| Built-in Filter Reference |
| | 405 | |
| | 405 | |
| | 405 | |
| | 405 | |
| | 405 | |
| | 405 | |
| | 406 | |
| | 406 | |
| | 406 | |
| | 406 | |
| | 406 | |
| | 406 | |
| | 407 | |
| | 407 | |
| | 407 | |
| | 407 | |
| | 407 | |
| | 408 | |
| | 408 | |
| | 408 | |
| | 408 | |
| | 409 | |
| | 409 | |
| | 409 | |
| | 409 | |
| | 409 | |
| | 409 | |
| | 410 | |
| | 410 | |
| | 410 | |
| | 410 | |
| | 410 | |
| | 411 | |
| | 411 | |
| | 411 | |
| | 411 | |
| | 411 | |
| | 411 | |
| | 412 | |
| | 412 | |
| | 412 | |
| | 412 | |
| | 412 | |
| | 413 | |
| | 413 | |
| | 413 | |
| | 413 | |
| | 414 | |
| | 414 | |
| | 414 | |
| | 414 | |
| APPENDIX G The django-admin Utility |
| | 415 | |
| | 415 | |
| | 416 | |
| adminindex [appname appname ...] |
| | 416 | |
| createcachetable [tablename] |
| | 416 | |
| | 416 | |
| | 416 | |
| dumpdata [appname appname ...] |
| | 417 | |
| | 417 | |
| | 417 | |
| loaddata [fixture fixture ...] |
| | 417 | |
| reset [appname appname ...] |
| | 419 | |
| | 419 | |
| runserver [optional port number, or ipaddr:port] |
| | 419 | |
| | 420 | |
| sql [appname appname ...] |
| | 420 | |
| sqlall [appname appname ...] |
| | 420 | |
| sqlclear [appname appname ...] |
| | 420 | |
| sqlcustom [appname appname ...] |
| | 420 | |
| sqlindexes [appname appname ...] |
| | 420 | |
| sqlreset [appname appname ...] |
| | 420 | |
| sqlsequencereset [appname appname ...] |
| | 421 | |
| | 421 | |
| startproject [projectname] |
| | 421 | |
| | 421 | |
| | 421 | |
| | 421 | |
| | 421 | |
| | 421 | |
| | 422 | |
| | 422 | |
| | 422 | |
| | 422 | |
| | 422 | |
| | 422 | |
| | 423 | |
| | 423 | |
| | 423 | |
| APPENDIX H Request and Response Objects |
| | 425 | |
| | 425 | |
| | 427 | |
| | 428 | |
| | 429 | |
| Construction HttpResponses |
| | 429 | |
| | 429 | |
| | 430 | |
| | 430 | |
| Customizing the 404 (Page Not Found) View |
| | 431 | |
| Customizing the 500 (Server Error) View |
| | 432 | |
| Index | | 433 | |