You are previewing Introduction to Tornado.
O'Reilly logo
Introduction to Tornado

Book Description

Tornado is a scalable, non-blocking web server and web application framework written in Python. It is also lightweight to deploy, fun to write for, and incredibly powerful. Tornado was written with performance in mind, aiming to solve the C10k problem, so by design it’s an extremely high-performance framework. It’s also packed with handy tools for dealing with social networks, user authentication, and all sorts of asynchronous fun. In this book, we’ll cover the basics of the Tornado framework, starting with the features that make it so great, and working our way towards some real-life examples. We’ll cover the best practices for implementation and deployment, as well as a sampling of uses for the technology.

Table of Contents

  1. Introduction to Tornado
  2. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  3. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. Safari® Books Online
    4. How to Contact Us
    5. Acknowledgements
  4. 1. Introduction
    1. What Is Tornado?
      1. Getting Started with Tornado
      2. Community and Support
    2. Simple Web Services
      1. Hello Tornado
        1. The handlers Parameter
        2. Specifying paths with regular expressions
      2. String Service
      3. More About RequestHandlers
        1. HTTP methods
        2. HTTP status codes
      4. Next Steps
  5. 2. Forms and Templates
    1. Simple Example: Poem Maker Pro
      1. Rendering Templates
      2. Interpolation
    2. Template Syntax
      1. Interpolating Expressions
      2. Control Flow Statements
      3. Using Functions Inside Templates
    3. Complete Example: The Alpha Munger
      1. How It Works
      2. Serving Static Files
        1. Setting the static_path
        2. Generating static URLs with static_url
      3. Next Steps with Templates
  6. 3. Extending Templates
    1. Blocks and Substitutions
      1. Basics of Blocks
      2. Templates in Practice: Burt’s Books
      3. Autoescaping
    2. UI Modules
      1. Basic Module Usage
      2. Modules in Depth
      3. Embedding JavaScript and CSS
    3. Summing Up
  7. 4. Databases
    1. Basic MongoDB Operations with PyMongo
      1. Establishing a Connection
      2. Dealing with Documents
      3. MongoDB Documents and JSON
    2. A Simple Persistent Web Service
      1. A Read-Only Dictionary
      2. Writing the Dictionary
    3. Burt’s Books
      1. Reading Books (From the Database)
      2. Editing and Adding Books
        1. Rendering the edit form
        2. Retrieving book information from the database
        3. Saving to the database
    4. MongoDB: Next Steps
  8. 5. Asynchronous Web Services
    1. Asynchronous Web Requests
      1. Starting Synchronous
      2. The Trouble with Blocking
      3. Basic Asynchronous Calls
      4. The asynchronous Decorator and the finish Method
      5. Asynchronous Generators
      6. Summary of Asynchronous Operations
    2. Long Polling with Tornado
      1. The Benefits of Long Polling
      2. Example: Live Inventory Reporting
      3. The Downsides of Long Polling
    3. WebSockets with Tornado
      1. Tornado’s WebSocket Module
      2. Example: Live Inventory with WebSockets
      3. The Future of WebSockets
  9. 6. Writing Secure Applications
    1. Cookie Vulnerabilities
      1. Cookie Forgery
      2. Secure Cookies
        1. Using Secure Cookies
        2. HTTP-Only and SSL Cookies
    2. Request Vulnerabilities
      1. Anatomy of a Cross-Site Request Forgery
      2. Defending Against Request Forgeries
      3. Using Tornado’s XSRF protection
        1. XSRF Tokens and AJAX Requests
    3. User Authentication
      1. Example: Welcome Back
      2. The authenticated Decorator
        1. The current_user property
        2. The login_url setting
    4. Summing up
  10. 7. Authenticating with External Services
    1. The Tornado auth Module
      1. The Authorization Workflow
      2. Asynchronous Requests
    2. Example: Sign in With Twitter
    3. Example: Facebook Authentication and the Graph API
  11. 8. Deploying Tornado
    1. Reasons for Running Multiple Tornado Instances
    2. Using Nginx as a Reverse Proxy
      1. Basic Nginx Configuration
      2. SSL Decryption with Nginx
    3. Using Supervisor to Manage Tornado Processes
  12. About the Authors
  13. SPECIAL OFFER: Upgrade this ebook with O’Reilly