Building Serverless Python Web Services with Zappa
上QQ阅读APP看书,第一时间看更新

Scaffolding

While implementing any project from scratch, you are free to design the scaffolding of your project. We are going to follow the scaffolding shown in the following screenshot:

Let's look at each directory and its uses in detail:

  • .env: This is our virtualenv directory, which has been created by the virtualenv command.
  • auth: We are going to create a standalone generic authentication module using the Flask-Login and Flask-SqlAlchemy extensions.
  • config: Here, we are going to create some configuration and generic database models, which may be needed by other modules.
  • static: It's Flask standard practice to put the static content under the static directory. Hence, we will be using this directory for all required static content.
  • templates: Flask has built-in support for the Jinja2 template engine and follows the standard layout for the template files based on the modules' names. We will see a detailed description of this later, when we actually utilize the templates.
  • todo: This is a standalone Flask module or package which has the basic to-do functionality.
  • __init__.py: This is Python's standard file that is required under a directory to build a Python package. We are going to write code here to configure our application.
  • migrations: This directory is autogenerated by Flask-Migrate. In a future section, we will see how Flask-Migrate works.
  • .gitignore: This contains a list of files and directories that should be ignored by Git versioning.
  • LICENSE: I have created a Git repository using GitHub and included an MIT license for our flask_todo repository.
  • README.md: This file is used to describe information about the repository on GitHub.
  • requirements.txt: This is the file where we listed all the required packages mentioned in the preceding section.
  • run.py: Here, we are going to create the final instance of our Flask application.
  • zappa_settings.json: This file gets generated by Zappa and has Zappa-related configurations.

We will look at a detailed explanation of the code in the upcoming sections.