Building Web Applications with Flask

Book description

Use Python and Flask to build amazing web applications, just the way you want them!

  • Learn how to use forms, authentication, and authorization control through extensions, and provide a robust, safe web experience for the client
  • Free yourself from the SQL vs NoSQL paradigm and use the technology that best fits your needs
  • Add powerful concepts like TDD and BDD to your range of testing skills

In Detail

Flask is a powerful web framework that helps you build great projects using your favorite tools. Flask takes the flexible Python programming language and provides a simple template for web development. Once imported into Python, Flask can be used to save time building web applications. It goes against the flow with the microframework concept, leaving most of the architecture choices to the developer. Through its great API, extensions, and powerful patterns, Flask helps you create simple projects in minutes and complex ones as soon as possible.

From the beginning, Building Web Applications with Flask shows you how to utilize Flask's concepts, extensions, and components to create engaging, full-featured web projects. You'll learn how to properly handle forms using WTForms, devise convenient templates with Jinja2 tags and macros, use NoSQL and SQL databases to store user data, test your projects with features and unit tests, create powerful authentication and user authorization, as well as administrative interfaces with ease, and more.

As Flask does not enforce an architectural recipe, neither do we! This book makes no coding assumptions on how you should code, leaving you free to experiment.

What You Will Learn

  • Create single page applications with Flask
  • Use macros, filters, tags, and control structures to render rich responses to user requests
  • Receive forms securely through form-based classes and WTForms
  • Utilize NoSQL or SQL databases to store user data seamlessly
  • Generate simple, yet powerful, REST services from your data models
  • Learn how to perform test-driven and behavior-driven developments in your Flask projects
  • Use Flask components to create maintainable non-flat projects
  • Harvest the power of extensions to build robust authorization and permission policies

Table of contents

  1. Building Web Applications with Flask
    1. Table of Contents
    2. Building Web Applications with Flask
    3. Credits
    4. About the Author
    5. About the Reviewers
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Flask in a Flask, I Mean, Book
      1. An introduction to Flask and its features
      2. Summary
    9. 2. First App, How Hard Could it Be?
      1. Hello World
      2. Prerequisites and tools
      3. Setting up a virtual environment
      4. Understanding the "Hello World" app
      5. Serving HTML pages
      6. Summary
    10. 3. Man, Do I Like Templates!
      1. What is Jinja2 and how is it coupled with Flask?
      2. What can you do with Jinja2?
        1. Control structures
        2. Macros
        3. Extensions
        4. Filters
        5. Messing with the template context
      3. Summary
    11. 4. Please Fill in This Form, Madam
      1. HTML forms for the faint of heart
      2. Handling forms
      3. WTForms and you
      4. Flask-WTF
        1. Integration with WTForms
        2. Securing forms with a CSRF token
        3. Challenges
      5. Summary
    12. 5. Where Do You Store Your Stuff?
      1. SQLAlchemy
        1. Concepts
        2. Hands on
        3. Flask-SQLAlchemy
      2. MongoDB
        1. MongoEngine
        2. Flask-MongoEngine
      3. Relational versus NoSQL
      4. Summary
    13. 6. But I Wanna REST Mom, Now!
      1. Beyond GET
      2. Flask-Restless
      3. Summary
    14. 7. If Ain't Tested, It Ain't Game, Bro!
      1. What kinds of test are there?
        1. Unit testing
        2. Behavior testing
        3. Flask-testing
          1. LiveServer
          2. Extra assertions
          3. JSON handle
      2. Fixtures
        1. Extra – integration testing
      3. Summary
    15. 8. Tips and Tricks or Flask Wizardry 101
      1. Overengineering
      2. Premature optimization
      3. Blueprints 101
      4. Oh God, please tell me you have the logs…
      5. Debugging, DebugToolbar, and happiness
        1. Flask-DebugToolbar
      6. Sessions or storing user data between requests
      7. Exercise
      8. Summary
    16. 9. Extensions, How I Love Thee
      1. How to configure extensions
      2. Flask-Principal and Flask-Login (aka Batman and Robin)
        1. Admin like a boss
        2. Custom pages
      3. Summary
    17. 10. What Now?
      1. You deploy better than my ex
        1. Placing your code in a server
        2. Setting up your database
        3. Setting up the web server
      2. StackOverflow
      3. Structuring your projects
      4. Summary
      5. Postscript
    18. Index

Product information

  • Title: Building Web Applications with Flask
  • Author(s): Italo Maia
  • Release date: June 2015
  • Publisher(s): Packt Publishing
  • ISBN: 9781784396152