How to Host Your Flask App for Free with PythonAnywhere
Hi, I'm Kitle.
When running a professional business or a large-scale system, you’d typically use services like AWS or other major hosting providers. However, for Python developers, there is a fantastic free hosting alternative.
While it has some limitations regarding web server configurations, I highly recommend it for lightweight web apps. The site is www.pythonanywhere.com. One small catch: you need to click an "Extend" button once every three months to keep it active (though it remains completely free). You can always upgrade to a paid plan or migrate to another service later. I personally liked it so much that I'm now using their paid tier.
Let’s jump straight into building a web server using PythonAnywhere.
1. Registration and Navigation
1. Sign up at www.pythonanywhere.com. The process is simple—just register and verify your email.
2. Log in and navigate to Consoles > Start a new Console > Other: Bash.
01:18 ~ $
2. Creating a Virtual Environment & Installing Packages
Once you're in the console, we’ll create a virtual environment. This prevents package conflicts between different projects.
01:18 ~ $ python3 -m venv myvenv
*myvenv is the name of our virtual environment. Unless you have a specific reason, just follow along with this name.
Confirm creation:
01:19 ~ $ ls
README.txt myvenv
If successful, you’ll see the myvenv folder.
Activate the environment:
01:21 ~ $ source myvenv/bin/activate
(myvenv) 01:21 ~ $

When you see (myvenv) at the start of the line, you're in! Remember this command; you'll use it often.
Install Flask:
(myvenv) 01:23 ~ $ pip3 install flask
Wait a moment, and you'll see a "Successfully installed" message. Now, let’s create a folder for our project files to keep things organized.
(myvenv) 01:23 ~ $ mkdir mysite
After creating the folder, click the PythonAnywhere logo (Home) to exit the Bash console.
3. Configuring the Web Tab
Go to the Web menu tab and click "Add a new web app". Follow the prompts, but choose "Manual Configuration" (or Custom settings) instead of the default Flask option. Your site will be accessible at USERNAME.pythonanywhere.com.
Now, let's edit the settings in the Web tab:
1. Find Code: WSGI configuration file and click to edit it.
2. Delete everything inside and paste this:
import sys path = '/home/YOURNAME/mysite' if path not in sys.path: sys.path.insert(0, path) from flask_app import app as application
*Replace YOURNAME with your actual PythonAnywhere username. Save the file.
3. Back in the Web tab, go to the Virtualenv section and enter your path:
/home/YOURNAME/myvenv

4. Creating the Server File
Now we need the actual Python code to run the server. Create a file named flask_app.py on your computer and paste this code:
from flask import Flask, request, make_response
app = Flask(__name__)
@app.route('/')
def home():
return 'Hello, World!'
if __name__ == '__main__':
app.run()
Go to the Files tab on PythonAnywhere, navigate to /home/YOURNAME/mysite, and upload flask_app.py here.
5. Accessing Your Website
Everything is set! Open your browser and type in: YOURNAME.pythonanywhere.com.

If you see "Hello, World!", you've succeeded! Your web app is now live and accessible from anywhere in the world.
Troubleshooting: If you see an error, click the RELOAD button in the Web tab. If it still doesn't work, check the "Error log" links at the bottom of the Web page to see what went wrong. It's quite straightforward once you get the hang of it!
Reference: https://help.pythonanywhere.com/pages/Flask/
- Kitle