Flask tutorial: How to deploy and publish an app on pythonanywhere
TLDR; In this tutorial I describe every step on how to deploy and publish your app on pythonanywhere. I am personally really convinced by the hosting service. If you are creating an account via my affliate links you support my work and further tutorials in this direction.

Overview
- Create a beginner account
- Initialize a web app
- Available Plans
- Setup Backend
- Web Configuration
Create a beginner account
Click this link to start: pythonanywhere.com*. You can start with a beginner account. It is totally free for three months and comes with https encryption and MySQL Database.


You will be redirected and you can start the tour.

Also, do not forget to confirm your email adress.

Initialize a web app
(1) We can start now to add a new web app. It is pretty easy. Go to Web tab.

And add a new web app.

It is openening a window, if you have a paid account, you could enter a customized url. But, it is not relevant for now, you can modify it later.

Select a python framework, just choose “manual configuration” and select a python version. I chose 3.9.


Et voilà done!

Available Plans
Later, if you feel comfortable, you can do the “Hacker“ Plan for 5 $ USD. Is it enough for running a basic website like a portfolio. I had it for almost one year. Then I changed to “Web dev” plan, because I implemented another webpage. You can also customize any plan by parameters like CPU, number of apps or disk space. Compared to other services like digital ocean it is way cheaper, because you have so much extra included.


Setup Backend
Go to the Console tab and open a new bash console.

Clone my repo from github.

Create a virtual environment for your webapp. Here is a good help on how to do it: https://help.pythonanywhere.com/pages/Virtualenvs/.
mkvirtualenv webpage_env --python=/usr/bin/python3.9

Now, we have to install the required libraries.
pip install -r requirements.txt
Web Configuration
Next, head to the tab Web on pythonanywhere and set up last configurations:
Under Code, set up your “source code” directory, where your app folder is:

You get the information when initializing the virtual environment in your bash console:

Then, configure the wsgi.py as following.

Below
++++++++++ FLASK +++++++++++
uncomment the lines for import sys and change your working directory as above. Also, edit your import statement. In this case our run.py file is the main file.
from run import app as application

Comment any other lines and save your changes.
Also, put the directory for your virtual environment under Virtualenv

Then reload and go to the url: http://testaccountab2022.pythonanywhere.com/

Enable HTTPS also:

It should display:

Congratulations you are done!
Just modify this example to your needs and run it on pythonanywhere.com* for it.
Thanks for reading my article. I hope you liked it. Please feel free to like, share, and comment on it. Follow me on more content about cryptos, stocks, data analysis and web development. I am hosting my apps on pythonanywhere.com*.
- Read my other article about creating a financial dashboard in flask
- Check out my webpage and get in touch with me on linkedin: antonioblago.com
- Make a free account on my stock and crypto tracking tool: www.tenxassets.com
- If you like to develop web apps, I recommend you pythonanywhere.com*
Disclaimer
*affliate links