Web 2.0 Programming with Django and Turbogear.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
Professional Python® Frameworks Web 2.0 Programming with Django® and TurboGears™ Dana Moore Raymond Budd William Wright Wiley Publishing, Inc. ffirs.indd v 9/8/07 3:32:26 PM ffirs.indd iv 9/8/07 3:32:26 PM Professional Python® Frameworks Web 2.0 Programming with Django® and TurboGears™ Acknowledgments ....................................................................................... xiii Introduction ................................................................................................ xxi Part I: Introduction to Python Frameworks Chapter 1: Web 2.0, Python, and Frameworks .................................................3 Chapter 2: Web 2.0 with Traditional Python ..................................................19 Chapter 3: Introducing the Frameworks ........................................................47 Part II: TurboGears Chapter 4: Introduction to TurboGears ........................................................101 Chapter 5: User Identity and Visitor Tracking ..............................................137 Chapter 6: Widgets ................................................................................... 169 Chapter 7: Advanced TurboGears Topics .....................................................203 Part III: Django Chapter 8: Dblog: A Blog Implemented in Django ........................................241 Chapter 9: Django Views and Users ............................................................275 Chapter 10: Advanced Django Topics: AJAX, RSS, and More ........................305 Part IV: Advanced Client-Side Topics Chapter 11: MochiKit — Pythonic JavaScripting .........................................337 Chapter 12: Flash-Based Interfaces and TurboGears ................................... 359 Appendix A: Tools Used ............................................................................ 395 Index ........................................................................................................ 405 ffirs.indd i 9/8/07 3:32:24 PM ffirs.indd ii 9/8/07 3:32:26 PM Professional Python® Frameworks Web 2.0 Programming with ® ™ Django and TurboGears ffirs.indd iii 9/8/07 3:32:26 PM ffirs.indd iv 9/8/07 3:32:26 PM Professional Python® Frameworks Web 2.0 Programming with Django® and TurboGears™ Dana Moore Raymond Budd William Wright Wiley Publishing, Inc. ffirs.indd v 9/8/07 3:32:26 PM Professional Python® Frameworks: Web 2.0 Programming Django® and TurboGears™ Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN-13: 978-0-470-13809-0 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 Library of Congress Cataloging-in-Publication Data Moore, Dana, 1947- Professional Python frameworks : Web 2.0 programming with Django and Turbogears / Dana Moore, Raymond Budd, William Wright. p. cm. Includes index. ISBN 978-0-470-13809-0 (pbk.) 1. Web site development. 2. Python (Computer program language) I. Budd, Raymond, 1976- II. Wright, William, 1964- III. Title. TK5105.888.M663 2007 006.7'6—dc22 2007032138 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or ex- tended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, account- ing, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Website is referred to in this work as a citation and/or a potential source of further in- formation does not mean that the author or the publisher endorses the information the organization or Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Python is a registered trademark of Python Soft- ware Foundation. Django is a registered trademark of The World Company Corporation. TurboGears is a trade- mark of Kevin Dangoor. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. ffirs.indd vi 9/8/07 3:32:27 PM For Jane, who, in our 35 years of love, has encouraged in me the belief that I can reach for and attain higher goals than I could ever imagine. And for my cherished daughter Caitlin, who is for me both luminous and a conductor of light; both possessing genius and having the power to stimulate it in others. —DM For Leah. You continually amaze me with your thoughtfulness, unwavering support, and above all your remarkable ability to make me laugh and smile. Also for my sisters, who have helped me out so many different times in so many different ways. —RB For my two favorite girls, Karan and Annette. Your encouragement and inspiration make all things seem possible. —WW ffirs.indd vii 9/8/07 3:32:28 PM ffirs.indd viii 9/8/07 3:32:28 PM About the Authors Dana Moore is a division scientist with BBN Technologies and is an acknowledged expert in the fields of peer-to-peer and collaborative computing, software agent frameworks, and assistive environments. Prior to joining BBN, Dana was chief scientist for Roku Technologies and a distinguished member of technical staff at Bell Laboratories. Dana is a popular conference speaker and a university lecturer. He has written articles for numerous computing publications and coauthored the books Peer-to-Peer: Building Secure, Scalable, and Manageable Networks; Jabber Developer’s Handbook; and Rich Internet Applications. Dana holds a Master of Science degree from the University of Maryland and a Bachelor of Science degree in industrial design, also from the University of Maryland. Raymond Budd is a software engineer with BBN Technologies. He has designed, developed, and sup- ported a variety of web applications and other distributed systems in Java, Ruby, and Python. He has been published in several conference proceedings such as the Eighteenth National Conference on Artificial Intelligence and journals including Applied Intelligence. Additional areas of interest include knowledge representations, knowledge engineering, and distributed planning and scheduling. He received a Bache- lor of Science degree in computer science from the University of Pittsburgh. William Wright is a senior principal investigator with SPARTA, where he develops networking software for systems distributed across the globe. His interests include real-time embedded systems, software architecture for reuse, and software agent frameworks. A frequent conference speaker, William has also written for Dr. Dobb’s Journal, Java Developer’s Journal, and Embedded Systems Programming, among others. He coauthored the books Jabber Developer’s Handbook and Beginning Java Networking. William holds a Master of Science degree in computer science from George Mason University and a Bachelor of Music degree in education from Indiana University. ffirs.indd ix 9/8/07 3:32:28 PM ffirs.indd x 9/8/07 3:32:29 PM Credits Acquisitions Editor Vice President and Executive Group Publisher Jenny Watson Richard Swadley Development Editor Vice President and Executive Publisher Maureen Spears Joseph B. Wikert Production Editor Project Coordinator Elizabeth Ginns Britten Adrienne Martinez Copy Editor Proofreader Kathryn Duggan Candace English Editorial Manager Indexer Mary Beth Wakefield Jack Lewis Production Manager Anniversary Logo Design Tim Tate Richard Pacifico ffirs.indd xi 9/8/07 3:32:29 PM ffirs.indd xii 9/8/07 3:32:29 PM Acknowledgments The authors wish to thank the industry leaders who shared