Flask Web Development: Developing Web Applications with Python

advertisement

Flask Web Development: Developing Web Applications with Python

Flask Web Development
Flask Web Development

Introduction 

    Flask stands out from other frameworks because it lets developers take the driver’s seat and have full creative control of their applications. Maybe you have heard the phrase “fighting the framework” before. This happens with most frameworks when you decide to solve a problem with a solution that isn’t the official one. It could be that you want to use a different database engine, or maybe a different method of authenticating users. Deviating from the path set by the framework’s developers will give you lots of headaches.

    Flask is not like that. Do you like relational databases? Great. Flask supports them all. Maybe you prefer a NoSQL database? No problem at all. Flask works with them too. Want to use your own homegrown database engine? Don’t need a database at all? Still fine. With Flask you can choose the components of your application, or even write your own if that’s what you want.

Digital electronics and Logic design

Flask is a great fit in three main instances:

  1. experimentation with the architecture, libraries, and newest technologies;
  2. unknown number of highly specialized (micro)services;
  3. multitude of small, disparate features.

advertisement

Table of Contents

1. Installation

  • Creating the Application Directory 2
  • Virtual Environments 2
  • Creating a Virtual Environment with Python 3 3
  • Creating a Virtual Environment with Python 2 3
  • Working with a Virtual Environment 4
  • Installing Python Packages with pip 5

2. Basic Application Structure

  • Initialization 7
  • Routes and View Functions 8
  • A Complete Application 9
  • Development Web Server 10
  • Dynamic Routes 12
  • Debug Mode 13
  • Command-Line Options 15
  • The Request-Response Cycle 17
  • Application and Request Contexts 17
  • Request Dispatching 18
  • The Request Object 19
  • Request Hooks 20
  • Responses 21
  • Flask Extensions

3. Templates

  • The Jinja2 Template Engine 26
  • Rendering Templates 26
  • Variables 27
  • Control Structures 28
  • Bootstrap Integration with Flask-Bootstrap 30
  • Custom Error Pages 33
  • Links 36
  • Static Files 37
  • Localization of Dates and Times with Flask-Moment 38

4. Web Forms

  • Configuration 44
  • Form Classes 44
  • HTML Rendering of Forms 47
  • Form Handling in View Functions 48
  • Redirects and User Sessions 51
  • Message Flashing 53

5. Databases

  • SQL Databases 57
  • NoSQL Databases 58
  • SQL or NoSQL? 59
  • Python Database Frameworks 59
  • Database Management with Flask-SQLAlchemy 61
  • Model Definition 62
  • Relationships 64
  • Database Operations 66
  • Creating the Tables 66
  • Inserting Rows 66
  • Modifying Rows 68
  • Deleting Rows 68
  • Querying Rows 68
  • Database Use in View Functions 71
  • Integration with the Python Shell 72
  • Database Migrations with Flask-Migrate 73
  • Creating a Migration Repository 73
  • Creating a Migration Script 74
  • Upgrading the Database 75
  • Adding More Migrations
Download full PDF in Comment section

advertisement

1 Comments

Previous Post Next Post