So, today we'll learn how to host our flask code online without any charges.
Requirements
[ That's it for free hosting ]
Steps
- Create an account in Python Anywhere
- Click on Web TAB and click on Add a new web app button in the left side
- Click on Next button below
- Select flask from the options below
- Select the latest python version from list
- Edit the file name of your project in the end. I'm editing with mine as app.py
- A new folder with /mysite will be created in our file manager. Click on Files TAB from the navigation bar. Click on the /mysite directory in the left corner.
- If you need to create directory, follow the left corner textbox, write the directory name & click New Directory button.
- Upload the files here.
N.B. - You can't upload multiple files at a time. Also, if there exist any directory, you need to create one & then upload files.
- Once again navigate to Web TAB & click on Reload USERNAME.pythonanywhere.com ; where USERNAME is your username
- That's it. Your site is live now. Let's check mine!
Getting some error? Try some of the below debugging :
- Try to update & install the libraries/modules which may not be installed in your Python Anywhere account. Navigate to the Files TAB & then to the /mysite folder & click on Open bash console here hyperlink.
- Type the following command in console
pip install -r requirements.txt
[ If you have a requirements.txt file]
In case you don't have, check how to create one from here
- All the required dependencies will be installed.
- Now go back to Web TAB & click on Reload USERNAME.pythonanywhere.com ; where USERNAME is your username.
- Another is the config file. We call it as WSGI config file. You could find it in Web TAB only.
- Click on the file name to edit the config file.
- Check all the contents should be like below code:
import sys
# add your project directory to the sys.path
project_home = '/home/name01001/mysite'
if project_home not in sys.path:
sys.path = [project_home] + sys.path
# import flask app but need to call it "application" for WSGI to work
from app import app as application # noqa
- Click on Save button
- Now go back to Web TAB & click on Reload USERNAME.pythonanywhere.com ; where USERNAME is your username.
I've tried to teach how to host Python (Flask) app for free in the simplest manner possible. However, if you're facing any difficulty, do mention it in the comment. Wil try to help.
You can follow me on LinkedIn, Instagram or check my latest projects on my GitHub. Also, you can check my portfolio too.
[Keep Coding] [Thanks]
Top comments (0)