What is Flask?
Flask is an API of Python that allows us to build up web-applications. Flask's framework is more explicit and easier to learn because it has less base code to implement a simple web-Application.
How Do I Set up Flask?
- Before starting the process, take a backup of your app.py file ( this is because Flask uses App.py as against Django that uses wsgi.py) as you will need to replace the content when setup is done.
- On your cPanel dashboard, click on Setup Python App and click on Create Application.
- Set the python version to the one compatible with the application you want to host.
- Set the application root to the location of your application.
NOTE: Your files cannot be directly under public_html, so it should be in a subfolder e.g /home/user/public_html/myappfiles in your case, this is why we was used: public_html/Flaskapp.
- Set the application URL you wish to use when setting up your application.
- Set the application startup file to the location of your App.py file, when setting up yours. E.g: /home/yourusername/public_html/Flaskapp/app.py.
- Set the entry point to the name of your application as declared in the App.py file.
- Set the passenger log file to the location where you want error logs to be saved.
- Click on create.
- After this is done, go to the App.py file and replace the content with that of the backed-up file (this is because Cpanel overwrites the file in the App.py file to confirm that the app is working and this has to be replaced with the original content for the app to work properly).
- Input the full path to your requirement.txt file in the CONFIGURATION FILES option. E.g **home/yourusername/public_html/Flaskapp/requirements.txt** and click on the add button.
- After the requirement file is added, click on the RUN PIP INSTALL button and select the file you added to install requirements and dependencies for the application.
- Restart the application.