www.it-ebooks.info
Python 3 Web Development
Beginner's Guide
Use Python to create, theme, and deploy unique web
applicaons
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 transmied in any form or by any means, without the prior wrien permission of the
publisher, except in the case of brief quotaons embedded in crical arcles or reviews.
Every eort has been made in the preparaon of this book to ensure the accuracy of the
informaon presented. However, the informaon 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 informaon about all of the
companies and products menoned in this book by the appropriate use of capitals. However,
Packt Publishing cannot guarantee the accuracy of this informaon.
First published: May 2011
Producon 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 ()
www.it-ebooks.info
Credits
Author
Michel Anders
Reviewers
Michael Driscoll
Róman Joost
Tomi Juhola
Andrew Nicholson
Herjend Teny
Acquision 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
Producon Coordinator
Kruthika Bangera
Cover Work
Kruthika Bangera
www.it-ebooks.info
About the Author
Michel Anders, aer his chemistry and physics studies where he spent more me on
computer simulaons 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 dierent
companies, including an Internet provider, a hospital, and a soware development company.
Aer his inial exposure to Python as the built-in scripng 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 wring his rst book, Blender 2.49
Scripng (Packt Publishing, 978-1-849510-40-0).
He loves to help people with Blender and Python-related quesons and may be contacted as
'varkenvarken' at
and maintains a blog on Python-
specic subjects at />For Clemenne, 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 ninees. He graduated from the University with
a Bachelors of Science degree, majoring in Management Informaon Systems. Michael
enjoys programming for fun and prot. His hobbies include Biblical apologecs, blogging
about Python at 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
mes they share with me. Most of all, I want to thank Jesus for saving me
from myself.
Róman Joost discovered open source soware in 1997. He is the project manager for
user documentaon for GNU Image Manipulaon Program (GIMP). Róman also helped with
German internaonalizaon of GIMP. He has been contribung to GIMP and Zope open
source projects for eight years.
Róman has a Diplom-Informaker (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
relaxaon, he enjoys photography and digital painng with GIMP.
www.it-ebooks.info
Tomi Juhola is a soware 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 nancial company and shares this me between development lead
dues and helping other projects to adopt Scrum and Agile methodologies. He likes to spend
his free me with new interesng 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 compung technologies. He is currently a Technical Director
with Innite Recursion Pty Ltd.—a bespoke soware engineering company located in Sydney,
Australia. He is a passionate advocate and a parcipant in the free, libre, and open source
soware (FLOSS) community and has acvely parcipated since 1999 contribung code,
ideas, and energy in this engineering community. He was a Technical Reviewer for the book
Python Tesng: 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
/>people/
.
www.it-ebooks.info
www.PacktPub.com
Support les, eBooks, discount offers, and more
You might want to visit www.PacktPub.com for support les and downloads related to your
book.
Did you know that Packt oers eBook versions of every book published, with PDF and ePub
les available? You can upgrade to the eBook version at
www.PacktPub.com and as a print
book customer, you are entled to a discount on the eBook copy. Get in touch with us at
for more details.
At
www.PacktPub.com, you can also read a collecon of free technical arcles, sign up for a
range of free newsleers, and receive exclusive discounts and oers on Packt books and eBooks.
Do you need instant soluons to your IT quesons? PacktLib is Packt's online digital book
library. Here, you can access, read and search across Packt's enre 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 enrely free books. Simply use your login credenals for
immediate access.
www.it-ebooks.info
www.it-ebooks.info
Table of Contents
Preface 1
Chapter 1: Choosing Your Tools 7
Idenfying the components of a web applicaon 7
Time for acon – geng an overview of a web applicaon 8
Choosing suitable tools 10
Time for acon – choosing a delivery framework, also known as web server 11
Time for acon – choosing a server-side scripng language 12
Time for acon – choosing a database engine 14
Time for acon – deciding on object relaonal mappers 15
Time for acon – choosing a presentaon framework 17
Designing for maintainability and usability 18
Tesng 18
Time for acon – choosing a test framework 19
Version management 19
Usability 20
Good looking – adhering to common GUI paradigms 20
Themable 21
Cross-browser compable 21
Cross-plaorm compable 22
Maintainability 22
Standards compliant 22
Security 23
Reliable 23
Robust 23
Access control and authencaon 24
Condenality 24
Integrity 25
A nal word on security 25
Help, I am confused! 25
Time for acon – maintaining overview 26
Summary 28
www.it-ebooks.info
Table of Contents
[ ii ]
Chapter 2: Creang a Simple Spreadsheet 29
Python 3 30
Time for acon – installing Python 3 CherryPy 30
Time for acon – installing CherryPy 31
Installing jQuery and jQuery UI 31
Serving an applicaon 32
Time for acon – serving a dummy applicaon 33
Time for acon – serving HTML as dynamic content 34
Who serves what: an overview 36
HTML: separang form and content 37
Time for acon – a unit convertor 38
HTML: form-based interacon 39
JavaScript: using jQuery UI widgets 40
Time for acon – conversion using unitconverter.js 40
jQuery selectors 42
CSS: applying a jQuery UI theme to other elements 43
Time for acon – converng a unit convertor into a plugin 45
JavaScript: creang a jQuery UI plugin 46
Designing a spreadsheet applicaon 51
Time for acon – serving a spreadsheet applicaon 51
HTML: keeping it simple 52
JavaScript: creang a spreadsheet plugin 52
The missing parts 58
Summary 58
Chapter 3: Tasklist I: Persistence 59
Designing a tasklist applicaon 59
Time for acon – creang a logon screen 62
Serving a logon screen 69
Seng up a session 70
Expiring a session 71
Designing a task list 72
Time for acon – running tasklist.py 72
Python: the task module 75
Time for acon – implemenng the task module 76
Adding new tasks 80
Deleng a task 81
JavaScript: tasklist.js 83
Time for acon – styling the buons 83
JavaScript: toolp.js 85
Time for acon – implemenng 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 lesystem 92
Choosing a database engine 92
Database-driven authencaon 93
Time for acon – authencaon using a database 94
Tasklist II – storing tasks in a database 99
Improving interacvity with AJAX 99
Time for acon – geng the me with AJAX 100
Redesigning the Tasklist applicaon 102
Database design 103
Time for acon – creang the task database 103
Time for acon – retrieving informaon with select statements 105
TaskDB – interfacing with the database 106
Time for acon – connecng to the database 106
Time for acon – storing and retrieving informaon 107
Time for acon – updang and deleng informaon 109
Tesng 111
Time for acon – tesng factorial.py 112
Now what have we gained? 113
Time for acon – wring unit tests for tasklistdb.py 114
Designing for AJAX 116
Click handlers 120
The applicaon 121
Time for acon – pung it all together 123
Have a go hero – refreshing the itemlist on a regular basis 125
Summary 126
Chapter 5: Enes and Relaons 127
Designing a book database 127
The Enty class 128
Time for acon – using the Enty class 129
Time for acon – creang instances 132
The Relaon class 138
Time for acon – using the Relaon class 138
Relaon instances 141
Time for acon – dening the Books database 144
The delivery layer 150
Time for acon – designing the delivery layer 151
Time for acon – adding a new book 162
www.it-ebooks.info
Table of Contents
[ iv ]
Auto compleon 165
Time for acon – using input elds with auto compleon 166
The presentaon layer 168
Time for acon – using an enhanced presentaon layer 168
Summary 170
Chapter 6: Building a Wiki 171
The data layer 172
Time for acon – designing the wiki data model 172
The delivery layer 175
Time for acon – implemenng the opening screen 176
The structural components 177
The applicaon methods 179
Time for acon – implemenng a wiki topic screen 180
Time for acon – eding wiki topics 182
Addional funconality 185
Time for acon – selecng an image 185
Time for acon – implemenng a tag cloud 190
Time for acon – searching for words 192
The importance of input validaon 195
Time for acon – scrubbing your content 196
Time for acon – rendering content 200
Summary 201
Chapter 7: Refactoring Code for Reuse 203
Time for acon – taking a crical look 203
Refactoring 205
Time for acon – dening new enes: how it should look 205
Metaclasses 206
Time for acon – using metaclasses 207
MetaEnty and AbstractEnty classes 208
Time for acon – implemenng the MetaEnty and AbstractEnty classes 209
Relaons 217
Time for acon – dening new relaons: how it should look 217
Implemenng the MetaRelaon and AbstractRelaon classes 219
Adding new methods to exisng classes 222
Browsing lists of enes 224
Time for acon – using a table-based Enty browser 224
Time for acon – examining the HTML markup 229
Caching 232
The books applicaon revisited 236
Time for acon – creang a books applicaon, take two 236
Summary 242
www.it-ebooks.info
Table of Contents
[ v ]
Chapter 8: Managing Customer Relaons 243
A crical review 243
Designing a Customer Relaonship Management applicaon 244
Time for acon – implemenng a basic CRM 244
Adding and eding values 248
Time for acon – adding an instance 249
Time for acon – eding an instance 251
Adding relaons 257
Picklists 259
Time for acon – implemenng picklists 259
Summary 262
Chapter 9: Creang Full-Fledged Webapps: Implemenng Instances 263
Even more relaons 263
Time for acon – showing one-to-many relaonships 264
Time for acon – adapng MetaRelaon 266
Time for acon – enhancing Display 270
Time for acon – enhancing Browse 271
Access control 274
Time for acon – implemenng access control 275
Role-based access control 278
Time for acon – implemenng role-based access control 279
Summary 283
Chapter 10: Customizing the CRM Applicaon 285
Time for acon – sorng 285
Time for acon – ltering 290
Customizaon 292
Time for acon – customizing enty displays 292
Time for acon – customizing enty lists 298
Time for acon – adding a delete buon 301
Summary 302
Appendix A: References to Resources 303
Good old oine reference books 303
Addional websites, wikis, and blogs 304
Appendix B: Pop Quiz Answers 307
Chapter 2, Creang a Simple Spreadsheet 307
Chapter 3, Tasklist I: Persistence 308
Chapter 4, Tasklist II: Databases and AJAX 309
Chapter 5, Enes and Relaons 310
Chapter 6, Building a Wiki 310
Index 311
www.it-ebooks.info
www.it-ebooks.info
Preface
Building your own Python web applicaons provides you with the opportunity to have great
funconality, with no restricons. However, creang web applicaons with Python is not
straighorward. Coupled with learning a new skill of developing web applicaons, you would
normally have to learn how to work with a framework as well.
Python 3 Web Development Beginner's Guide shows you how to independently build your
own web applicaon that is easy to use, performs smoothly, and is themed to your taste—all
without having to learn another web framework.
Web development can take me and is oen ddly to get right. This book will show you
how to design and implement a complex program from start to nish. Each chapter looks
at a dierent type of web applicaon, meaning that you will learn about a wide variety
of features and how to add them to your customized web applicaon. You will also learn
to implement jQuery into your web applicaon to give it extra funconality. By using the
right combinaon of a wide range of tools, you can have a fully funconal, complex web
applicaon up and running in no me.
A praccal guide to building and customizing your own Python web applicaon, without the
restricon of a pre-dened framework.
What this book covers
Chapter 1, Choosing Your Tools, looks at the many aspects of designing web applicaons.
The idea is to provide you with an overview that may help you recognize components in
subsequent chapters and give you some insight into the arguments used to decide which
tool or library to use. We also illustrate some issues that are relevant when designing an
applicaon that does not deal with coding directly, such as security or usability.
Chapter 2, Creang a Simple Spreadsheet, develops a simple spreadsheet applicaon. The
spreadsheet funconality will be enrely implemented in JavaScript plus jQuery UI, but
on the server-side, we will encounter the applicaon server, CherryPy, for the rst me
and we will extend it with Python code to deliver the page that contains the spreadsheet
applicaon dynamically.
www.it-ebooks.info
Preface
[ 2 ]
Chapter 3, Tasklist I: Persistence, a full edged web applicaon needs funconality to store
informaon on the server and a way to idenfy dierent users. In this chapter, we address
both issues as we develop a simple applicaon to maintain lists of tasks.
Chapter 4, Tasklist II: Databases and AJAX, refactors the tasklist applicaon developed in
the previous chapter. We will use the SQLite database engine on the server to store items
and will use jQuery's AJAX funconality to dynamically update the contents of the web
applicaon. On the presentaon side, we will encounter jQuery UI's event system and will
learn how to react on mouse clicks.
Chapter 5, Enes and Relaons, most real life applicaons sport more than one enty and
oen many of these enes are related. Modeling these relaons is one of the strong points
of a relaonal database. In this chapter, we will develop a simple framework to manage
these enes and use this framework to build an applicaon to maintain lists of books for
mulple users.
Chapter 6, Building a Wiki, develops a wiki applicaon and in doing so we focus on two
important concepts in building web applicaons. The rst one is the design of the data layer.
The wiki applicaon is quite complex, and in this chapter, we try to see where the limitaons
in our simple framework lie. The second one is input validaon. Any applicaon that accepts
input from all over the Internet should check the data it receives, and in this chapter, we look
at both client-side and server-side input validaon.
Chapter 7, Refactoring Code for Reuse, aer doing a substanal bit of work, it is oen a good
idea to take a step back and look crically at your own work to see if things could have been
done beer. In this chapter, we look at ways to make the enty framework more generally
useful and employ it to implement the books applicaon a second me.
Chapter 8, Managing Customer Relaons, there is more to an enty framework and CherryPy
applicaon code than merely browsing lists. The user must be able to add new instances and
edit exisng ones. This chapter is the start of the development of a CRM applicaon that will
be extended and rened in the nal chapters.
Chapter 9, Creang Full-Fledged Webapps: Implemenng Instances, focuses on the design
and implementaon of the user interface components to add and maintain enes,
and relaons between enes, in a way that is independent of the type of enty. This
funconality is immediately put to use in the CRM applicaon that we develop. Managing
user privileges is another issue we encounter as we explore the concept of role-based access
control.
Chapter 10, Customizing the CRM Applicaon, is the nal chapter and it extends our
framework and thereby our CRM applicaon by taking a look at browsing, ltering,
and sorng large numbers of enes. We also take a look at what is needed to allow
customizaon by the end user of the applicaon's appearance and its funconality.
www.it-ebooks.info
Preface
[ 3 ]
Appendix A, References to Resources, is a convenient overview of both Web and paper
resources.
What you need for this book
Besides a computer running Windows or Linux to develop and test your applicaons, you will
need the following pieces of open source soware:
Python 3.2
CherryPy 3.2.0
jQuery 1.4.4
jQuery UI 1.8.6
How to obtain and install these packages is explained in detail in Chapter 2. We also use
some addional plugins for jQuery and provide installaon instrucons where appropriate.
You will also need a web browser to interact with your applicaons. The applicaons were
tested on Firefox 3 and Internet Explorer 8, but any moderately recent versions of these
browsers will probably work just as well, as will Chrome. The Firebug extension for Firefox,
however, is a superior tool to debug the client-side of web applicaons, so you might want to
try it if you have not done so already. Appendix A provides links to the necessary resources.
Finally, you will need a text editor, preferably with syntax highlighng capabilies for Python
as well as JavaScript and HTML. The author uses Notepad++ (
http://notepad-plus-
plus.org/
) on Windows and JOE ( on Linux,
but the choice is enrely up to you.
Who this book is for
Moderately experienced Python programmers who want to learn how to create fairly
complex, database-driven, cross browser compable web applicaons that are maintainable
and look good, will nd this book of most use. All applicaons in the book are developed
in Python 3, but experience with Python 2.x is sucient to understand all examples.
JavaScript plays an important supporng role in many of the example applicaons and some
introductory level knowledge of JavaScript might be useful, but is not strictly necessary
because the focus is mainly on Python development and the JavaScript code is used either
as building blocks or explained in such detail that anyone comfortable with Python should be
able to understand it.
www.it-ebooks.info
Preface
[ 4 ]
Conventions
In this book, you will nd several headings appearing frequently.
To give clear instrucons of how to complete a procedure or task, we use:
Time for action – heading
1. Acon 1
2. Acon 2
3. Acon 3
Instrucons oen need some extra explanaon so that they make sense, so they are
followed with:
What just happened?
This heading explains the working of tasks or instrucons that you have just completed.
You will also nd some other learning aids in the book, including:
Pop quiz – heading
These are short mulple choice quesons intended to help you test your own understanding.
Have a go hero – heading
These set praccal challenges and give you ideas for experimenng with what you have
learned.
You will also nd a number of styles of text that disnguish between dierent kinds of
informaon. Here are some examples of these styles, and an explanaon of their meaning.
Code words in text are shown as follows: "Running CherryPy's
setup.py script installs a
number of modules in Python's Lib\site-packages directory."
A block of code is set as follows:
<div id="main">
<ul>
<li>one</li>
<li class="highlight">two</li>
<li>three</li>
</ul>
www.it-ebooks.info
Preface
[ 5 ]
</div>
<div id="footer">footer text</div>
When we wish to draw your aenon to a parcular part of a code block, the relevant lines
or items are set in bold:
t=t+'<thead class="ui-widget-header">
<tr class="ui-helper-reset"><th></th>';
for(i=0;i<opts.cols;i=i+1){
t=t+'<th class="ui-helper-reset">' +
String.fromCharCode(65+i)+"</th>";
}
Any command-line input or output is wrien as follows:
python -c "import cherrypy"
New terms and important words are shown in bold. Words that you see on the screen, in
menus or dialog boxes for example, appear in the text like this: "New books or authors may
be added by clicking the Add new buon."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this
book—what you liked or may have disliked. Reader feedback is important for us to
develop tles that you really get the most out of.
To send us general feedback, simply send an e-mail to
, and
menon the book tle via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the
SUGGEST A TITLE form on
www.packtpub.com or e-mail
If there is a topic that you have experse in and you are interested in either wring or
contribung to a book, see our author guide on
www.packtpub.com/authors.
www.it-ebooks.info
Preface
[ 6 ]
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you
to get the most from your purchase.
Downloading the example code for this book
You can download the example code les for all Packt books you have purchased from your
account at . If you purchased this book elsewhere, you can
visit
and register to have the les e-mailed directly
to you.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do
happen. If you nd a mistake in one of our books—maybe a mistake in the text or the
code—we would be grateful if you would report this to us. By doing so, you can save other
readers from frustraon and help us improve subsequent versions of this book. If you
nd any errata, please report them by vising
selecng your book, clicking on the errata submission form link, and entering the details
of your errata. Once your errata are veried, your submission will be accepted and the
errata will be uploaded on our website, or added to any list of exisng errata, under the
Errata secon of that tle. Any exisng errata can be viewed by selecng your tle from
/>Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt,
we take the protecon of our copyright and licenses very seriously. If you come across any
illegal copies of our works, in any form, on the Internet, please provide us with the locaon
address or website name immediately so that we can pursue a remedy.
Please contact us at
with a link to the suspected pirated material.
We appreciate your help in protecng our authors, and our ability to bring you valuable
content.
Questions
You can contact us at if you are having a problem with any
aspect of the book, and we will do our best to address it.
www.it-ebooks.info
1
Choosing Your Tools
In this chapter, we look at the many aspects of designing web applicaons.
The idea is to provide you with an overview that may help you recognize
components in subsequent chapters and give you some insight into the
arguments used to decide which tool or library to use.
Also, as this book covers more than just developing example applicaons, we
illustrate some issues that are relevant when designing an applicaon that does
not deal with coding directly, like security or usability.
In this chapter, we will be:
Indenfying the components that a web applicaon consists of
Choosing suitable tools
Considering what designing for maintainability and usability implies
There is a lot of ground to cover, so let's get started.
Identifying the components of a web application
A web applicaon is not a monolithic object. In designing such an applicaon, it might
help focus if you look at an applicaon as a collecon of related objects, each with its well-
dened purpose. This can be done with mulple levels of detail and even the mile high view
may already give some valuable insights.
www.it-ebooks.info
Choosing Your Tools
[ 8 ]
Time for action – getting an overview of a web application
From the following picture shown, it should be clear that a web applicaon is not a singular
thing. It consists of parts that reside on a server and parts that run on the computer of the
user. Both halves are just as important; although the server may hold the applicaon data
and implement the logic to modify that data following requests from the user, the data is
displayed by the part of the web applicaon running in the browser on the client computer
and the user signals his/her request by interacng with the user interface components in the
browser, for example, by clicking on an "OK" buon.
Think about your applicaon and consider both server and client-side. The
advantage of looking at the individual halves is that we might make choices
that are opmal for the specic half.
Look at the general requirements for the client half. For example, because we want
to oer the user a sophiscated user interface, we opt for the jQuery UI library. This
decision does not touch the overall design decision on the server, because apart
from delivering the les that the jQuery UI library consists of, the choice of user
interface library has no impact on the choice of the database engine or the server
operang system for example.
Look at the requirements for the server half. For example, consider which
implementaon language to use. We select Python as the language to implement
the server-side code but if we had compelling arguments to switch to C#, we could
do so without the need to change anything on the client.
If we zoom in on our web applicaon, an image emerges of many interacng layers, each
encapsulang a well dened piece of funconality. Everywhere two layers touch, informaon
ows through a well dened interface (API). This helps in the separaon of concepts (our
applicaon is only talking to the database layer to store and retrieve persistent data and only
to the web server to return data upon request) but in pracce, the separaon between these
layers isn't completely clear in all circumstances. For example, the server-side part of our
applicaon is actually an integral part of the web server.
This simple schemac of a web applicaon is virtually idencal to a regular client-server
architecture. However, when we look more closely at the implementaon of the client and
the interacon between client and server, dierences will emerge as we will see in the next
secon where we zoom in a bit closer.
www.it-ebooks.info
Chapter 1
[ 9 ]
What just happened?
With both halves of the applicaon idened, we can now zoom in on each individual half.
This will enable us to get a more detailed image, that will help us to make informed decisions
regarding the smaller components that make up our applicaon.
The main components are easy to idenfy:
The data store holds data on the server (it is oen a database engine, somemes
just les on the lesystem).
The server-side applicaon services requests that are passed through from the web
server.
The web server forwards those responses to the client again and may serve stac
les as well.
The web browser takes care of running the client side of the applicaon, but within the
browser, we can idenfy several layers of acvies. These consist of:
Fetching the content to structure the data (oen HTML les)
Running JavaScript code to enhance the presentaon of the data
Allowing interacon with the user
Of course we could zoom in even further to reveal addional detail like the operang
system on the client and the server, or even the hardware and the network components and
although occasionally useful, this would generally be overkill. With the main components
clearly idened, we can take the next step and choose suitable tools to implement these
components.
www.it-ebooks.info
Choosing Your Tools
[ 10 ]
Choosing suitable tools
If you want to develop quality applicaons, you need suitable tools. Tools, of course, do not
guarantee quality, but they can make life a lot easier. When developing web applicaons,
there are two kinds of tools you need to consider: the ones you use to design, build, test,
and deploy your applicaon, like editors, version management systems, test frameworks,
and maybe a package tool, and the tools that deliver your applicaon to the end user. That
last set of tools consists of a whole chain of components, from server operang system, web
server, and database engine, all the way to the web browser and the JavaScript libraries used
to display and interact with the applicaon.
When we start a project, we have to know which tools we need and have to understand the
capabilies and limitaons of the many variaons of these tools. There are, for example,
quite a few JavaScript libraries that may be used to provide cross-browser compable user
interacon.
The trick is to make an informed choice. These choices are not necessarily limited to open
source tools. If budget permits, it might be worthwhile to have the benet of the special
features many commercial development tools and libraries oer, but in this book, we limit
ourselves to open source and/or free resources. This makes sense as the cost of tooling and
licenses in small projects can make a signicant dent in a budget.
The opportunity to use free tools might not exist for the deployment environment. You may
well develop your applicaon on your own Linux box, but test and deploy it on a Windows
server. The laer needs a license that will not be free, but even open source opons are not
always free. Many companies nowadays shi to deploying their applicaons to the cloud
and even though these machines might be running an open source operang system, you
pay not only for CPU power and bandwidth but also for support, the laer being crucial in
applicaons that will lose you money if they are not running. However, using open source
tools in general gives you a much wider choice because many tools run equally well on any
plaorm.
In the following secons, we will look at the many components that make up the tool chain
and will try to show what arguments were used for the choices made for developing the
applicaons in this book and what (if any) viable alternaves are there. Note that some
arguments are quite subjecve and the choice nally made does not necessarily indicate that
the alternave is bad; we certainly are not aempng to start ame wars over which tool is
beer. We simply list requirements for applicaon development as we see it and try to nd
the tools suitable for the task. In some situaons, another tool might be beer, but for this
book, we try to nd a matching toolset that can be used for all sample applicaons that are
free (as in beer) and easy to learn and use.
www.it-ebooks.info