Files

  1. Directory Structure
  2. main.py
  3. main.py
  4. word_file_app.py
    • word_file_app.py – library import
    • word_file_app.py – create_application

Directory Structure


main.py

Import some standard libraries, os and sys. They will be used later.

Next import our configuration file for the flask app, and our word_file_app which will talk about below.

Because we are just running the app locally we will set it to 127.0.0.1, in the config file you can set the port you would like to run on, I happen to use 7002.


word_file_app.py

Ok, now we will set up the flask app. We will import some standard items from the flask library, next our configuration file for this app, and lastly the different route files to be used in the flask blueprints. We will review all of those later on.

Now let’s go line by line.


word_file_app.py – library import

Importing OS standard library. Next from flask package we are importing the main Flask web handler, functions for sending files, functions for redirect webpages, blueprints, and the all important session.

The next section imports the configuration file for the app, we will cover the settings in the configuration file later on.

We are going to use four different route files. The reason being is that there really are four separate steps in creating the merged word document. Separating out into different blueprints allows us to keep the logic a little more contained.

routes.main_app, routes.maintain_file, routes.merge_file, routes.generate_file

word_file_app.py – create_application

In the main create_application function, we are doing the normal thing you would expect, we are creating the flask application, named app. The function is called from main.py

Next we read in the app_config file, and set the application configuration settings. We don’t have many configuration settings, but allows for future enahancements.

Next we register the blueprints.

routes.main_app, routes.maintain_file, routes.merge_file, routes.generate_file

This allows for all the different endpoints to be available to the application.

The inject_title function is a shortcut way of adding the page title to each of the html template pages we will use later on.

And lastly we return the app to the main.py.

Next we will go through the configuration pages, and how they are used.