Flask Setup - QuinnBast/SaskTel-Communication-Portal GitHub Wiki

Flask is a type of python project, which runs a web server to host files and routes to users. Flask can be configured like any other Python project. For this project, Python 3.6 is being used.

Setup

Step 1 - Creating a virtual environment

In order to use the project, a python virtual environment must be created in order to ensure that this project is running off of its own dependencies of python. If you are setting up the project in PyCharm, a virtual environment is automatically created for the project. However, if you are not using PyCharm, a virtual environment needs to be created.

Option 1: With PyCharm

  1. Close any open projects.
  2. Create a new project and "Checkout from Version Control"
  3. https://github.com/QuinnBast/SaskTel-Communication-Portal.git
  4. Ensure that a local virtual environment is created for the project in your project's settings (File->Settings->Project Interpreter)
    1. click the dropdown and click "select all"
    2. click the plus sign in the upper right corner, and then click apply.
    3. That's all, PyCharm will generate the rest.

Option 2: Using virtualenv

  1. Clone the github repository into the destination of your choice.
  2. Within the root folder of the repository, open the python command terminal
  3. Check to see if you have pip installed pip -h
  4. If the help appears, pip is installed, if not, install pip
  5. pip install virtualenv
  6. virtualenv venv
  7. venv\Scripts\activate -- This may need to be run from the windows command prompt instead of the python terminal

Step 2 - Installing Python dependencies

  1. Open a terminal and navigate to the root directory of the project
  2. Execute pip install -r requirements.txt

The dependencies that are being used for the project are listed below:

requests- For sending HTTP requests
flask - to run the flask server
flask_restful - to create REST endpoints
flask-jwt-extended - to create tokens for user authentication
PyYaml - for configuration of Flask

Step 3 - Change Configuration files

  1. Within the project navigate to the /REST/config/ProductionConfig.py file.
  2. Generate a secret key of any length and change the JWT_SECRET_KEY field.
  3. Navigate to the /REST/config/Config.py file.
  4. Ensure the configuration settings within the general config file are appropriate.

Click here For more information on configuration.

Step 4 - Running the Flask Server

Option 1: Via PyCharm (for development only!)

The flask server can be run inside of PyCharm to start a local web server where your content can be served from flask.

With PyCharm Professional:

In order to do this, create a new run configuration in PyCharm in the top right and add a new flask server run configuration. Set the target to REST.server and ensure you are using python 3.6 or above. Once configured click apply. Run the server with the play button.

With PyCharm Community:

At the bottom of PyCharm, open the terminal. Ensure you are in the SaskTel-Communication-Portal directory. Set the flask environment with the command set FLASK_APP=REST/server.py. This tells flask where the root file of the server is located. Run the server from the terminal by executing flask run

With WSGI Server:

TODO - write information on how to configure for apache2 and wsgi.

⚠️ **GitHub.com Fallback** ⚠️