If you follow programming as a hobby, you might have wanted to host your site for free, but couldn't find any free web hosts.
In this article, we will explore how to host a website built in Python. You can use any web development framework, but I will be using Flask for this tutorial.
Using PythonAnywhere to host your Python webapp:
To host our website, we will be using a tool called Python Anywhere. It is a free webhost, with several pricing plans for more advanced sites, primarily used to host Python websites.
As mentioned before, our site will have Flask at its core. We will also be using Bootstrap for the front end.
We will be creating a very minimal website just to understand the basics.
Setting up PythonAnywhere
Step1: Create a PythonAnywhere account:
This should be pretty self-explanatory, that in order to use pythonanywhere, we are going to have to create an account.
It is recommended to create a beginner account if you are just starting out.
Step2: Create a new webapp:
Once you are done with creating an account, you’ll be greeted by the dashboard.
Now, in order to proceed, we need to locate the web button in the navbar and click on it.
This will then redirect us to the webapps screen.
Click on "Add a new web app" button
Since we are using the beginner plan, we will not have a custom domain name.
Select "Flask" from the Select a Python Framework screen and click the "next" button
Select "Python 3.10" (Python versions 3.11 and 3.12 are currently not supported by Python anywhere, as of the time of writing this article).
Finally, enter the "Path" to your project and the name of the file that will contain our flask app. In our article, we will keep it at: /home/KushagraSTechies/src/main.py
And that is all! Once Flask has finished creating our webapp, we can look it up at
http://yourusername.pythonanywhere.com
PythonAnywhere has created a basic website for us.
You can now configure this website according to your wishes and can also import existing Flask projects into it.
PythonAnywhere also provides you with a bash shell, which allows you to import templates from git, use git control, and manage your Python virtual environments.
However, you also need to ensure that you have installed your project dependencies in the pythonanywhere bash shell.
Conclusion:
In this article, we learned how to host our website using a tool called pythonanywhere. It has both paid and free plans and allows freedom in designing the webapp.
We hope this article helps you in hosting your Python websites.