文件名称:Django 1.0 Website Development.pdf
文件大小:3.48MB
文件格式:PDF
更新时间:2022-09-03 07:04:14
Django 1.0 Website Development
Table of Contents Preface 1 Chapter 1: Introduction to Django 7 MVC pattern in web development 7 Why Python? 8 Why Django? 9 Tight integration between components 10 Object-Relational Mapper 10 Clean URL design 10 Automatic administration interface 10 Advanced development environment 10 Multilingual support 11 History of Django 11 Summary 12 Chapter 2: Getting Started 13 Installing the required software 13 Installing Python 13 Installing Python on Windows 14 Installing Python on UNIX/Linux 14 Installing Python on Mac OS X 15 Installing Django 15 Installing Django on Windows 15 Installing Django on UNIX/Linux and Mac OS X 16 Installing a database system 17 Creating your first project 18 Creating an empty project 18 Setting up the database 20 Launching the development server 22 Summary 23 This material is copyright and is licensed for the sole use by Richard Ostheimer on 15th June 2009 2205 hilda ave., , missoula, , 59801 Table of Contents [ ii ] Chapter 3: Building a Social Bookmarking Application 25 A word about Django terminology 25 URLs and views: creating the main page 26 Creating the main page view 26 Creating the main page URL 27 Models: designing an initial database schema 31 The link data model 32 The user data model 35 The bookmark data model 36 Templates: creating a template for the main page 38 Putting it all together: generating user pages 40 Creating the URL 40 Writing the view 41 Designing the template 42 Populating the model with data 44 Summary 45 Chapter 4: User Registration and Management 47 Session authentication 47 Creating the login page 48 Enabling logout functionality 53 Improving template structure 54 User registration 59 Django forms 59 Designing the user registration form 60 Account management 68 Summary 69 Chapter 5: Introducing Tags 71 The tag data model 72 Creating the bookmark submission form 75 Restricting access to logged-in users 80 Methods for browsing bookmarks 81 Improving the user page 83 Creating a tag page 85 Building a tag cloud 87 A word on security 90 SQL injection 91 Cross-Site Scripting (XSS) 91 Summary 93 This material is copyright and is licensed for the sole use by Richard Ostheimer on 15th June 2009 2205 hilda ave., , missoula, , 59801 Table of Contents [ iii ] Chapter 6: Enhancing the User Interface with AJAX 95 AJAX and its advantages 96 Using an AJAX framework in Django 97 Downloading and installing jQuery 98 The jQuery JavaScript framework 99 Element selectors 100 jQuery methods 100 Hiding and showing elements 101 Accessing CSS properties and HTML attributes 102 Manipulating HTML documents 103 Traversing the document tree 103 Handling events 104 Sending AJAX requests 105 What next? 105 Implementing live searching of bookmarks 105 Implementing basic searching 106 Implementing live searching 109 Editing bookmarks in place 112 Implementing basic bookmark editing 113 Implementing in-place editing of bookmarks 117 Auto-completion of tags 125 Summary 129 Chapter 7: Voting and Commenting 131 Sharing bookmarks on the main page 131 The SharedBookmark data model 132 Modifying the bookmark submission form 133 Browsing and voting for shared bookmarks 135 The popular bookmarks page 141 Commenting on bookmarks 144 Enabling the comments application 144 Creating a view for comments 145 Displaying comments and a comment form 147 Creating comment templates 149 Summary 153 Chapter 8: Creating an Administration Interface 155 Activating the administration interface 155 Customizing the administration interface 159 Customizing listing pages 160 Overriding administration templates 162 This material is copyright and is licensed for the sole use by Richard Ostheimer on 15th June 2009 2205 hilda ave., , missoula, , 59801 Table of Contents [ iv ] Users, groups, and permissions 164 User permissions 164 Group permissions 165 Using permissions in views 166 Summary 167 Chapter 9: Advanced Browsing and Searching 169 Adding RSS feeds 170 Creating the recent bookmarks feed 170 Customizing item fields 174 Creating the user bookmarks feed 175 Linking feeds to HTML pages 178 Advanced searching 179 Retrieving objects with the database API 180 Advanced queries with Q objects 183 Improving the search feature 184 Organizing content into pages (pagination) 185 Summary 190 Chapter 10: Building User Networks 191 Building friend networks 191 Creating the friendship data model 192 Writing views to manage friends 195 The friends list view 195 Creating the add friend view 198 Inviting friends via email 201 The invitation data model 202 The Invite A Friend form and view 205 Handling activation links 207 Improving the interface with messages 211 Summary 214 Chapter 11: Extending and Deploying 217 Internationalization (i18n) 217 Marking strings as translatable 218 Creating translation files 221 Enabling and configuring the i18n system 223 Improving performance with caching 226 Enabling caching 227 Local memory caching 227 Database caching 227 File system caching 227 Memcached 227 This material is copyright and is licensed for the sole use by Richard Ostheimer on 15th June 2009 2205 hilda ave., , missoula, , 59801 Table of Contents [ v ] Configuring caching 228 Caching the whole site 228 Caching specific views 229 Unit testing 229 The test client 230 Testing the registration view 232 Deploying Django 236 The production web server 237 The production database 237 Turning off debug mode 237 Changing configuration variables 238 Setting error pages 238 Summary 239 Chapter 12: What Next? 241 Custom template tags and filters 242 Model managers and custom SQL 243 Generic views 244 Contributed sub-frameworks 245 Flatpages 245 Sites 246 Markup filters 246 Humanize 247 Sitemaps 247 Cross-Site Request Forgery protection (CSRF) 247 Message system 248 Subscription system 249 User scores 249 Summary 250 Index 251