web2py Application Development Cookbook

web2py Application Development Cookbook
eBook: $29.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $79.98    Print cover: $49.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters

Take your web2py skills to the next level by dipping into delicious, usable recipes in this cookbook Learn advanced web2py usage from building advanced forms to creating PDF reports Written by developers of the web2py project with plenty of code examples for interesting and comprehensive learning  

Book Details

Language : English
Paperback : 364 pages [ 235mm x 191mm ]
Release Date : March 2012
ISBN : 1849515468
ISBN 13 : 9781849515467
Author(s) : Mariano Reingart, Bruno Cezar Rocha, Jonathan Lundell, Pablo Martin Mulone, Michele Comitini, Richard Gordon, Massimo Di Pierro
Topics and Technologies : All Books, Web Development, Cookbooks, Open Source, Python

Table of Contents

Chapter 1: Deploying web2py
Chapter 2: Building Your First Application
Chapter 3: Database Abstraction Layer
Chapter 4: Advanced Forms
Chapter 5: Adding Ajax Effects
Chapter 6: Using Third-party Libraries
Chapter 7: Web Services
Chapter 8: Authentication and Authorization
Chapter 9: Routing Recipes
Chapter 10: Reporting Recipes
Chapter 11: Other Tips and Tricks
  • Chapter 1: Deploying web2py
    • Introduction
    • Installing web2py on Windows (from source code)
    • Installing web2py in Ubuntu
    • Setting up a production deployment on Ubuntu
    • Running web2py with Apache, mod_proxy, and mod_rewrite
    • Running web2py with Lighttpd
    • Running web2py with Cherokee
    • Running web2py with Nginx and uWSGI
    • Running web2py on shared hosts using CGI
    • Running web2py on shared hosts with mod_proxy
    • Running web2py from a user-defined folder
    • Installing web2py as a service in Ubuntu
    • Running web2py with IIS as a proxy
    • Running web2py with ISAPI
    • Chapter 2: Building Your First Application
      • Introduction
      • Improving the scaffolding application
      • Building a simple contacts application
      • Building a Reddit clone
      • Building a Facebook clone
      • Using crud.archive
      • Converting an existing static site into a web2py application
      • Creating semi-static pages (flatpages)
      • Adding your custom logo
      • Creating menus and submenus
      • Customizing menus with icons
      • Creating a navigation bar
      • Using cookies to set the language
      • Designing modular applications
      • Speeding up downloads
      • Chapter 3: Database Abstraction Layer
        • Introduction
        • Creating a new model
        • Creating a model from a CSV file
        • Batch upload of your data
        • Moving your data from one database to another
        • Creating a model from existing MySQL and PostgreSQL databases
        • Efficiently searching by tag
        • Accessing your database from multiple applications
        • Hierarchical category tree
        • Creating records on demand
        • OR, LIKE, BELONGS, and more on Google App Engine
        • Replacing slow virtual fields with DB views
        • Chapter 4: Advanced Forms
          • Introduction
          • Adding confirmation on form submit
          • Searching data dynamically
          • Embedding multiple forms in one page
          • Detecting and blocking concurrent updates
          • Creating a form wizard
          • De-normalizing data temporarily
          • Removing form labels
          • Using fileuploader.js
          • Uploading files using a LOADed component
          • Making image thumbnails from uploaded images
          • Monitoring upload progress
          • Auto tooltips in forms
          • Color picker widget
          • Shortening text fields
          • Creating multi-table forms
          • Creating a multi-table form with references
          • Creating a multi-table update form
          • Star rating widget
          • Chapter 5: Adding Ajax Effects
            • Introduction
            • Using jquery.multiselect.js
            • Creating a select_or_add widget
            • Using an autocompletion plugin
            • Creating a drop-down date selector
            • Improving the built-in ajax function
            • Using a slider to represent a number
            • Using jqGrid and web2py
            • Improving data tables with WebGrid
            • Ajaxing your search functions
            • Creating sparklines
              • Chapter 7: Web Services
                • Introduction
                • Consuming a web2py JSON service with jQuery
                • Consuming a JSON-RPC service
                • JSON-RPC from JavaScript
                • Making amf3 RPC calls from Flex using pyamf
                • PayPal integration in Web2py
                • PayPal web payments standard
                • Getting Flickr photos
                • Sending e-mails with Boto through Amazon Web Services (AWS)
                • Making GIS amps using mapscript
                • Google groups and Google code feeds reader
                • Creating SOAP web services
                • Chapter 8: Authentication and Authorization
                  • Introduction
                  • Customizing Auth
                  • Using CAPTCHA on login failure
                  • Using pyGravatar to get avatars for user profile pages
                  • Multi-user and teacher modes
                  • Authenticating with Facebook using OAuth 2.0
                  • Chapter 9: Routing Recipes
                    • Introduction
                    • Making cleaner URLs with routes.py
                    • Creating a simple router
                    • Adding a URL prefix
                    • Associating applications with domains
                    • Omitting the application name
                    • Removing application name and controllers from URLs
                    • Replacing underscores with hyphens in URLs
                    • Mapping favicons.ico and robots.txt
                    • Using URLs to specify the language
                      • Chapter 11: Other Tips and Tricks
                        • Introduction
                        • Using PDB and the embedded web2py debugger
                        • Debugging with Eclipse and PyDev
                        • Updating web2py using a shell script
                        • Creating a simple page statistics plugin
                        • Rounding corners without images or JavaScript
                        • Setting a cache.disk quota
                        • Checking if web2py is running using cron
                        • Building a Mercurial plugin
                        • Building a pingback plugin
                        • Changing views for mobile browsers
                        • Background processing with a database queue
                        • How to effectively use template blocks
                        • Making standalone applications with web2py and wxPython

                        Mariano Reingart

                        Mariano Reingart lives in Buenos Aires (Argentina), and is a specialist in database administration, and development of software applications and libraries (web services, PDF, replication, and so on), with more than 10 years of experience. Currently, he is the PostgreSQL regional contact for Argentina and a web2py contributor, with more than 14 open source projects, including interface for Free Electronic Invoice web services (PyAfipWs) and Pythonic Replication for PostgreSQL (PyReplica). Mariano has a bachelor's degree in Computer Systems Analysis from the University of Morón, and currently works on his own funded startup formed by an open group of independent professionals, which is dedicated to software development, training, and technical support, focusing on open source tools (GNU/Linux, Python, PostgreSQL and web2py). Mariano has worked for local Python companies in large business applications (ERP, SCM, and CRM) and mission critical systems (election counting, electronic voting, and 911 emergency events support). He has contributed to the book web2py Enterprise Web Framework 3rd Edition, and for several Spanish translation efforts of the PostgreSQL official documentation. You can find his resume at: http://reingart.blogspot.com/p/resume.html.

                        Bruno Cezar Rocha

                        Bruno Cezar Rocha is a web developer and entrepreneur. He is the co-founder and lead developer at http://www.blouweb.com, a micro-company dedicated to web2py/Python web development and training. He is the lead teacher in Curso de Python (http://www. CursoDePython.com.br), an initiative to offer online courses of Python and web2py to Brazilian companies and educational institutes. He is the Vice President of the Python Brazilian Association, which is the organizer of PyCon Brazil, and other Python-related events in his country. He is an entrepeneur focused on SaaS products powered by web2py at http://www.ansy.me/en, which is a pioneer in web-based systems for veterinarians and pet shops, and creator of http://www.movu.ca, a social network engine and CMS powered by web2py. You can find his resume at: http://www.rochacbruno.com.br

                        Jonathan Lundell

                        Jonathan Lundell leveraged a background in the philosophy of Ludwig Wittgenstein, into an exciting career in computer systems design. These days, he uses web2py to provide cloud services to his iOS apps, written for Lobitos Creek. He's getting used to Objective-C, but can't help wishing that Steve Jobs had been a Python fan.

                        Pablo Martin Mulone

                        Pablo Martín Mulone is a full-time web developer and software designer. He co-runs his own company located in Argentina, which is dedicated to bring IT solution to libraries, archives, and government in matter of documentary preservation. He has an extensive experience in FLOSS projects and associated tools. He is the creator of instant2press and CMS/ blog that is developed in web2py framework. His company created the patrimoniosf. gov.ar heritage database, which was built for the state government of Santa Fe.

                        Michele Comitini

                        Michele Comitini is a programmer, a consultant, and an entrepreneur, with 20 years of experience in the field of open source software development. Michele has worked with many of the top Information and Communication Technology (ICT) companies in Italy. His skills include the ability to program in many languages and some of the most popular web frameworks. Michele was a Linux early adopter, and he has developed a deep knowledge of the Linux/Unix operating systems as well as its use in embedded systems. Michele is the owner and CEO of GliscoS.R.L., a consulting and development firm that is specialized in mission critical or highly customized software. His customers are mostly companies in the ICT and in the financial sectors.

                        Richard Gordon

                        Richard Gordon has 30 years of experience in agile web development and industrial design-automation software. He has a Master's degree in Electrical Engineering from Stanford University and a Science Baccalaureate with honors from Brown University. His career spans microprocessor design at AT&T Bell laboratories, electronic-design-automation, software development at Mentor Graphics and Tera Systems, which he founded. He is the founder and lead YAK at YAKiToMe! Co., the Internet's first text-to-speech SaaS portal.

                        Massimo Di Pierro

                        Massimo Di Pierro is an associate professor at the School of Computing of DePaul University in Chicago, where he directs the Master's program in Computational Finance. He also teaches courses on various topics, including web frameworks, network programming, computer security, scientific computing, and parallel programming. Massimo has a PhD in High Energy Theoretical Physics from the University of Southampton (UK), and he has previously worked as an associate researcher for Fermi National Accelerator Laboratory. Massimo is the author of a book on web2py, and more than 50 publications in the fields of Physics and Computational Finance, and he has contributed to many open source projects. He started the web2py project in 2007, and is currently the lead developer.
                        Sorry, we don't have any reviews for this title yet.

                        Code Downloads

                        Download the code and support files for this book.

                        Submit Errata

                        Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                        - 7 submitted: last submission 14 Jan 2014

                        Errata type: Others | Page number: 95 | Errata date: 12 June 2012 Change line: response.ajax='web2py_component("%s", "show_itemlist" % URL('showitems') To Line: response.headers['web2py-component-command']='web2py_component("%s", "showitems" % URL('list_items')  

                        Errata type: Typo | Page number: 56 | Errata date: July 3, 2013

                        This sentence:
                        This avoid unnecessarily reloading of the page, when a new log is inserted.
                        Should be:
                        This avoids unnecessarily reloading of the page, when a new log is inserted.

                        Errata type: Code | Page number: 19 | Errata date: July 4, 2013

                        The code block which reads:
                        <VirtualHost *:80>
                        #make sure that HTTP redirects generated by web2py are reverted
                        / -> /web2py/
                        ProxyPassReverse /web2py/ http://localhost:8000/
                        ProxyPassReverse /web2py/ /
                        # transform cookies also
                        ProxyPassReverseCookieDomain localhost localhost
                        ProxyPassReverseCookiePath / /web2py/
                        Is missing a comment on line 4 (which is corrected later when the code is
                        re-listed). Instead of line 4 reading:
                        / -> /web2py/
                        it should read:
                        # / -> /web2py/

                        Errata type: Typo | Page number: 70 | Errata date: July 4, 2013

                        Change this line:

                        We also need a callback action to implement to allow users to request friendship, to accept friendship, to deny a friendship request, and to cancel a previous request for friendship.


                        We also need a callback action to allow users to request friendship, to accept friendship, to deny a friendship request, and to cancel a previous request for friendship.

                        Errata type: Code | Page number: 64 | Errata date: July 9, 2013

                        Under item 2, the second sentence beneath the illustration on that page  
                        "... it expects a news ID as args(0), and plus or minus as args(0)...."
                        It should read:
                        "it expects a news ID as args(0), and plus or minus as args(1)"

                        Errata type: Code | Page number: 69 | Errata date: July 9, 2013

                        At the top of Pg 69 we find:
                        "# in file: models:"
                        This line should read:
                        "# in file: models:db.py"

                        Sample chapters

                        You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                        Frequently bought together

                        web2py Application Development Cookbook +    Applied Architecture Patterns on the Microsoft Platform =
                        50% Off
                        the second eBook
                        Price for both: $45.60

                        Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                        What you will learn from this book

                        Install web2py on windows from source code and run it on Apache, Lighttpd, and Nginx servers Build simple applications such as a contacts applications and a facebook clone Create a new model and batch upload your data Embed multiple forms in one page and create multi-table forms Improve the built-in AJAX function and AJAXify your search functions Generate PDF reports and charts Consume JSON service and integrate Paypal with web2py Debug with eclipse and PyDev, learn to build your own plugin  

                        In Detail

                        web2py is a free open source full-stack framework for rapid development of fast, scalable, secure and portable database-driven web-based applications. It is written and programmable in Python, and straightforward to run. web2py implements Model-View-Controller design, server-side form validation, and postbacks that make the code more readable, scalable, and maintainable. Are you familiar with web2py, and interested in gaining more advanced knowledge?web2py Application Development Cookbook gives you the necessary knowledge to make you a web2py expert. Right from teaching you about the database abstraction layer to adding AJAX effects to recipes about recipe, the book will make you a master of web2py through advanced practical recipes without any drudgery or straining the brain.web2py Application Development Cookbook is the tool you will need to expand and enhance your web2py skills.This book begins with teaching you running web2py in various different systems followed by building simple applications. It focuses on database abstraction layer next and then explains building advanced forms. Adding stunning AJAX effects, using third party libraries and recipes on web services follow. Advanced recipes on authentication and authorization are taught and then routing and reporting recipes claim your attention. There is a final wrap-up with useful, interesting tips and tricks which you will really enjoy.In short, this book will make you an expert in web2py in a trouble-free, quick, and easy manner.


                        This is a cookbook and you may read the chapters in any order. The recipes need not be read sequentially. There are a good amount of code examples and relevant screenshots to ease learning pains.

                        Who this book is for

                        The target audience are Python developers with basic knowledge of web2py who want to gain further knowledge of web2py.

                        Code Download and Errata
                        Packt Anytime, Anywhere
                        Register Books
                        Print Upgrades
                        eBook Downloads
                        Video Support
                        Contact Us
                        Awards Voting Nominations Previous Winners
                        Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                        Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software