DEV Community

Cover image for How to host your Flask app free online
Nitin Kumar
Nitin Kumar

Posted on

How to host your Flask app free online

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

Image description

  • Click on Web TAB and click on Add a new web app button in the left side

Image description

  • Click on Next button below

Image description

  • Select flask from the options below

Image description

  • Select the latest python version from list

Image description

  • Edit the file name of your project in the end. I'm editing with mine as app.py

Image description

  • 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.

Image description

  • If you need to create directory, follow the left corner textbox, write the directory name & click New Directory button.

Image description

  • 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.

Image description

  • Once again navigate to Web TAB & click on Reload USERNAME.pythonanywhere.com ; where USERNAME is your username

Image description

  • That's it. Your site is live now. Let's check mine!

Image description


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.

Image description

  1. 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

  1. All the required dependencies will be installed.

Image description

  1. Now go back to Web TAB & click on Reload USERNAME.pythonanywhere.com ; where USERNAME is your username.

Image description

  • Another is the config file. We call it as WSGI config file. You could find it in Web TAB only.

Image description

  1. Click on the file name to edit the config file.

Image description

  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. Click on Save button

Image description

  1. Now go back to Web TAB & click on Reload USERNAME.pythonanywhere.com ; where USERNAME is your username.

Image description

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)