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.
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.
- Close any open projects.
- Create a new project and "Checkout from Version Control"
https://github.com/QuinnBast/SaskTel-Communication-Portal.git
- Ensure that a local virtual environment is created for the project in your project's settings (File->Settings->Project Interpreter)
- click the dropdown and click "select all"
- click the plus sign in the upper right corner, and then click apply.
- That's all, PyCharm will generate the rest.
- Clone the github repository into the destination of your choice.
- Within the root folder of the repository, open the python command terminal
- Check to see if you have pip installed
pip -h
- If the help appears, pip is installed, if not, install pip
pip install virtualenv
virtualenv venv
-
venv\Scripts\activate
-- This may need to be run from the windows command prompt instead of the python terminal
- Open a terminal and navigate to the root directory of the project
- 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
- Within the project navigate to the
/REST/config/ProductionConfig.py
file. - Generate a secret key of any length and change the JWT_SECRET_KEY field.
- Navigate to the
/REST/config/Config.py
file. - Ensure the configuration settings within the general config file are appropriate.
Click here For more information on configuration.
The flask server can be run inside of PyCharm to start a local web server where your content can be served from flask.
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.
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
TODO - write information on how to configure for apache2 and wsgi.