Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Tài liệu Python 3 Web Development Beginner''''s Guide ppt
PREMIUM
Số trang
336
Kích thước
3.3 MB
Định dạng
PDF
Lượt xem
1840

Tài liệu Python 3 Web Development Beginner''''s Guide ppt

Nội dung xem thử

Mô tả chi tiết

www.it-ebooks.info

Python 3 Web Development

Beginner's Guide

Use Python to create, theme, and deploy unique web

applications

Michel Anders

BIRMINGHAM - MUMBAI

www.it-ebooks.info

Python 3 Web Development

Beginner's Guide

Copyright © 2011 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system,

or transmitted in any form or by any means, without the prior written permission of the

publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the

information presented. However, the information contained in this book is sold without

warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers

and distributors will be held liable for any damages caused or alleged to be caused directly or

indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the

companies and products mentioned in this book by the appropriate use of capitals. However,

Packt Publishing cannot guarantee the accuracy of this information.

First published: May 2011

Production Reference: 1060511

Published by Packt Publishing Ltd.

32 Lincoln Road

Olton

Birmingham, B27 6PA, UK.

ISBN 978-1-849513-74-6

www.packtpub.com

Cover Image by Rakesh Shejwal ([email protected])

www.it-ebooks.info

Credits

Author

Michel Anders

Reviewers

Michael Driscoll

Róman Joost

Tomi Juhola

Andrew Nicholson

Herjend Teny

Acquisition Editor

Sarah Cullington

Development Editor

Neha Mallik

Technical Editors

Sakina Kaydawala

Gauri Iyer

Copy Editor

Leonard D'Silva

Project Coordinators

Poorvi Nair

Michelle Quadros

Proofreader

Mario Cecere

Indexer

Tejal Daruwale

Graphics

Nilesh Mohite

Production Coordinator

Kruthika Bangera

Cover Work

Kruthika Bangera

www.it-ebooks.info

About the Author

Michel Anders, after his chemistry and physics studies where he spent more time on

computer simulations than on real world experiments, the author found his real interests

lay with IT and Internet technology, and worked as an IT manager for several different

companies, including an Internet provider, a hospital, and a software development company.

After his initial exposure to Python as the built-in scripting language of Blender, the popular

3D modeling and rendering suite, the language became his tool of choice for many projects.

He lives happily in a small converted farm, with his partner, three cats, and twelve goats.

This tranquil environment proved to be ideally suited to writing his first book, Blender 2.49

Scripting (Packt Publishing, 978-1-849510-40-0).

He loves to help people with Blender and Python-related questions and may be contacted as

'varkenvarken' at http://www.blenderartists.org/ and maintains a blog on Python￾specific subjects at http://michelanders.blogspot.com/.

For Clementine, always.

www.it-ebooks.info

About the Reviewers

Michael Driscoll has been programming Python since the Spring of 2006 and has

dabbled in other languages since the late nineties. He graduated from the University with

a Bachelors of Science degree, majoring in Management Information Systems. Michael

enjoys programming for fun and profit. His hobbies include Biblical apologetics, blogging

about Python at http://www.blog.pythonlibrary.org/, and learning photography.

Michael currently works for the local government, where he does programming with Python

as much as possible. Michael was also a Technical Reviewer for Python 3: Object Oriented

Programming by Dusty Phillips and Python Graphics Cookbook by Mike Ohlson de Fine (both

by Packt Publishing).

I would like to thank my friends and family for their support and the fun

times they share with me. Most of all, I want to thank Jesus for saving me

from myself.

Róman Joost discovered open source software in 1997. He is the project manager for

user documentation for GNU Image Manipulation Program (GIMP). Róman also helped with

German internationalization of GIMP. He has been contributing to GIMP and Zope open

source projects for eight years.

Róman has a Diplom-Informatiker (FH) from the University of Applied Sciences in Koethen

(Anhalt). He has worked for Zope companies—Gocept GmbH & Co in Germany, Infrae in

The Netherlands, and is currently working for a Zope company in Brisbane, Australia. For

relaxation, he enjoys photography and digital painting with GIMP.

www.it-ebooks.info

Tomi Juhola is a software development professional from Finland. He has a wide range of

development experience from embedded systems to modern distributed enterprise systems

in various roles such as tester, developer, consultant, and trainer.

Currently, he works in a financial company and shares this time between development lead

duties and helping other projects to adopt Scrum and Agile methodologies. He likes to spend

his free time with new interesting development languages and frameworks.

He has reviewed conference proposals, a Python development book, and has also published

his own Master's theses on Agile embedded development.

Andrew Nicholson is a computer engineer with over fourteen years of professional

experience in a broad range of computing technologies. He is currently a Technical Director

with Infinite Recursion Pty Ltd.—a bespoke software engineering company located in Sydney,

Australia. He is a passionate advocate and a participant in the free, libre, and open source

software (FLOSS) community and has actively participated since 1999 contributing code,

ideas, and energy in this engineering community. He was a Technical Reviewer for the book

Python Testing: Beginner's Guide (2010), Packt Publishing.

Nicholson has a B.Eng (Computer) [Honours 1] from Newcastle University, Australia and a

M.Eng (Wireless) with Merit from Sydney University, Australia.

Nicholson's biography can be read at http://www.infiniterecursion.com.au/

people/.

www.it-ebooks.info

www.PacktPub.com

Support files, eBooks, discount offers, and more

You might want to visit www.PacktPub.com for support files and downloads related to your

book.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub

files available? You can upgrade to the eBook version at www.PacktPub.com and as a print

book customer, you are entitled to a discount on the eBook copy. Get in touch with us at

[email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a

range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

http://PacktLib.PacktPub.com

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book

library. Here, you can access, read and search across Packt's entire library of books.

Why Subscribe?

‹ Fully searchable across every book published by Packt

‹ Copy and paste, print and bookmark content

‹ On demand and accessible via web browser

Free Access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access

PacktLib today and view nine entirely free books. Simply use your login credentials for

immediate access.

www.it-ebooks.info

www.it-ebooks.info

Table of Contents

Preface 1

Chapter 1: Choosing Your Tools 7

Identifying the components of a web application 7

Time for action – getting an overview of a web application 8

Choosing suitable tools 10

Time for action – choosing a delivery framework, also known as web server 11

Time for action – choosing a server-side scripting language 12

Time for action – choosing a database engine 14

Time for action – deciding on object relational mappers 15

Time for action – choosing a presentation framework 17

Designing for maintainability and usability 18

Testing 18

Time for action – choosing a test framework 19

Version management 19

Usability 20

Good looking – adhering to common GUI paradigms 20

Themable 21

Cross-browser compatible 21

Cross-platform compatible 22

Maintainability 22

Standards compliant 22

Security 23

Reliable 23

Robust 23

Access control and authentication 24

Confidentiality 24

Integrity 25

A final word on security 25

Help, I am confused! 25

Time for action – maintaining overview 26

Summary 28

www.it-ebooks.info

Table of Contents

[ ii ]

Chapter 2: Creating a Simple Spreadsheet 29

Python 3 30

Time for action – installing Python 3 CherryPy 30

Time for action – installing CherryPy 31

Installing jQuery and jQuery UI 31

Serving an application 32

Time for action – serving a dummy application 33

Time for action – serving HTML as dynamic content 34

Who serves what: an overview 36

HTML: separating form and content 37

Time for action – a unit convertor 38

HTML: form-based interaction 39

JavaScript: using jQuery UI widgets 40

Time for action – conversion using unitconverter.js 40

jQuery selectors 42

CSS: applying a jQuery UI theme to other elements 43

Time for action – converting a unit convertor into a plugin 45

JavaScript: creating a jQuery UI plugin 46

Designing a spreadsheet application 51

Time for action – serving a spreadsheet application 51

HTML: keeping it simple 52

JavaScript: creating a spreadsheet plugin 52

The missing parts 58

Summary 58

Chapter 3: Tasklist I: Persistence 59

Designing a tasklist application 59

Time for action – creating a logon screen 62

Serving a logon screen 69

Setting up a session 70

Expiring a session 71

Designing a task list 72

Time for action – running tasklist.py 72

Python: the task module 75

Time for action – implementing the task module 76

Adding new tasks 80

Deleting a task 81

JavaScript: tasklist.js 83

Time for action – styling the buttons 83

JavaScript: tooltip.js 85

Time for action – implementing inline labels 86

www.it-ebooks.info

Table of Contents

[ iii ]

CSS: tasklist.css 87

Summary 90

Chapter 4: Tasklist II: Databases and AJAX 91

The advantages of a database compared to a filesystem 92

Choosing a database engine 92

Database-driven authentication 93

Time for action – authentication using a database 94

Tasklist II – storing tasks in a database 99

Improving interactivity with AJAX 99

Time for action – getting the time with AJAX 100

Redesigning the Tasklist application 102

Database design 103

Time for action – creating the task database 103

Time for action – retrieving information with select statements 105

TaskDB – interfacing with the database 106

Time for action – connecting to the database 106

Time for action – storing and retrieving information 107

Time for action – updating and deleting information 109

Testing 111

Time for action – testing factorial.py 112

Now what have we gained? 113

Time for action – writing unit tests for tasklistdb.py 114

Designing for AJAX 116

Click handlers 120

The application 121

Time for action – putting it all together 123

Have a go hero – refreshing the itemlist on a regular basis 125

Summary 126

Chapter 5: Entities and Relations 127

Designing a book database 127

The Entity class 128

Time for action – using the Entity class 129

Time for action – creating instances 132

The Relation class 138

Time for action – using the Relation class 138

Relation instances 141

Time for action – defining the Books database 144

The delivery layer 150

Time for action – designing the delivery layer 151

Time for action – adding a new book 162

www.it-ebooks.info

Table of Contents

[ iv ]

Auto completion 165

Time for action – using input fields with auto completion 166

The presentation layer 168

Time for action – using an enhanced presentation layer 168

Summary 170

Chapter 6: Building a Wiki 171

The data layer 172

Time for action – designing the wiki data model 172

The delivery layer 175

Time for action – implementing the opening screen 176

The structural components 177

The application methods 179

Time for action – implementing a wiki topic screen 180

Time for action – editing wiki topics 182

Additional functionality 185

Time for action – selecting an image 185

Time for action – implementing a tag cloud 190

Time for action – searching for words 192

The importance of input validation 195

Time for action – scrubbing your content 196

Time for action – rendering content 200

Summary 201

Chapter 7: Refactoring Code for Reuse 203

Time for action – taking a critical look 203

Refactoring 205

Time for action – defining new entities: how it should look 205

Metaclasses 206

Time for action – using metaclasses 207

MetaEntity and AbstractEntity classes 208

Time for action – implementing the MetaEntity and AbstractEntity classes 209

Relations 217

Time for action – defining new relations: how it should look 217

Implementing the MetaRelation and AbstractRelation classes 219

Adding new methods to existing classes 222

Browsing lists of entities 224

Time for action – using a table-based Entity browser 224

Time for action – examining the HTML markup 229

Caching 232

The books application revisited 236

Time for action – creating a books application, take two 236

Summary 242

www.it-ebooks.info

Table of Contents

[ v ]

Chapter 8: Managing Customer Relations 243

A critical review 243

Designing a Customer Relationship Management application 244

Time for action – implementing a basic CRM 244

Adding and editing values 248

Time for action – adding an instance 249

Time for action – editing an instance 251

Adding relations 257

Picklists 259

Time for action – implementing picklists 259

Summary 262

Chapter 9: Creating Full-Fledged Webapps: Implementing Instances 263

Even more relations 263

Time for action – showing one-to-many relationships 264

Time for action – adapting MetaRelation 266

Time for action – enhancing Display 270

Time for action – enhancing Browse 271

Access control 274

Time for action – implementing access control 275

Role-based access control 278

Time for action – implementing role-based access control 279

Summary 283

Chapter 10: Customizing the CRM Application 285

Time for action – sorting 285

Time for action – filtering 290

Customization 292

Time for action – customizing entity displays 292

Time for action – customizing entity lists 298

Time for action – adding a delete button 301

Summary 302

Appendix A: References to Resources 303

Good old offline reference books 303

Additional websites, wikis, and blogs 304

Appendix B: Pop Quiz Answers 307

Chapter 2, Creating a Simple Spreadsheet 307

Chapter 3, Tasklist I: Persistence 308

Chapter 4, Tasklist II: Databases and AJAX 309

Chapter 5, Entities and Relations 310

Chapter 6, Building a Wiki 310

Index 311

www.it-ebooks.info

www.it-ebooks.info

Tải ngay đi em, còn do dự, trời tối mất!