DEV Community

Cover image for 4 Free hosting platforms for python web app with step-by-step process
Yash Makan
Yash Makan

Posted on

4 Free hosting platforms for python web app with step-by-step process

Hi developers, I am Yash Makan and in today's post, we are going to discuss 4 platforms where you can host your flask or Django app. If you've completed a website or API using python or planning to create one then this post is so right for you. Also, read till the end as in the end, I am going to explain step by step the complete process of uploading your web app to the internet. So without any further ado let's start!

https://i.giphy.com/media/dpsUFSR9ZHjwfrVAg9/giphy.webp

What is a hosting platform and why do I need one?

Alright! If you have developed a web app then you might know that all these apps whether made with Django or flask run on localhost. A localhost is a place where you can run your code and view it in your browser. But when you complete the development of your web app then it might be time to publish your app on the internet so that anyone can access your websites. A web app setup locally can be viewed by you but your friends won't be able to see your amazing work. There are two options you can opt-in these situations.

  • One is to connect your localhost with a tunnel using ngrok. Ngrok exposes your localhost to the internet so that everyone can access it by a specific URL provided by it. I don't recommend this way if you want your website 24x7 as you have to run your program 24x7 which is quite not the case but if you just want to share your localhost for some time and you don't want the connection to be connected then you can choose this method. For more info, you can read it here by Abayomi Ogunnusi.
  • The second way is to host your code to someone else's server. This someone else server is what we call the hosting platform. Here these servers run your code 24x7 at some specific domain. So if you want to host then below are your best options according to me.

Trulli


bye-bye localhost

Below all the links are compared based on their hobby or free packs

0. Vercel (full step-by-step procedure at the end)

✅ Git connect

✅ Custom domain

✅ CLI available

✅ deploy and manage multiple versions

✅ deploy ease

✅ HTTPS/SSL

No Project limit

32 deployments every 1 hour

1. qovery

✅ Git connect with auto-deploy

✅ Great community support with discord

✅ HTTPS/SSL

✅ Inbuilt database integration like PostgreSQL, MySQL

✅ CLI available

up to 3 projects with 100 applications

According to my personal experience, it's a little tricky to deploy the web app on qovery

100 deployments a month

2. pythonanywhere

✅ Git connect

✅ deploy ease

✅ HTTPS/SSL

CLI is not available

No custom domain

You cannot deploy and manage multiple versions of your web app

You can make one project per account

There is internet outbound so you won't be able to scrape most of the websites you want to.

3. Heroku

✅ Git connect and deploy

550-1,000 dyno hours per month

5 apps(unverified accounts) & up to 100 apps(verified accounts)

web app sleeps when no activity detects

It's not that easy to deploy like others on the list

My Recommendations

Vercel is the winner for sure for me. It has everything for free that I want and I will recommend vercel to you guys as well.

How can I deploy my flask web app on vercel?

  1. download node from https://nodejs.org/en/ and make sure npm is accessible from your terminal by npm -v
  2. Download vercel cli using npm i -g vercel. Refer here
  3. add requirements.txt file with all the python packages mentioned you've used.
  4. Create your account on https://vercel.com/. It's pretty straightforward...
  5. add vercel.json file and add the below content(here I am using app.py as my main file)


{
  "version": 2,
  "builds": [
      {
          "src": "*.py",
          "use": "@liudonghua123/now-flask"
      }
  ],
  "routes": [
      {
          "src": "(.*)",
          "dest": "app.py"
      }
  ]
}


Enter fullscreen mode Exit fullscreen mode
  1. make sure your project looks something like this

    Project structure

  2. open terminal at the root of the project.

  3. Type the below commands

    Vercel in cmd

    Vercel commands

  4. And there you have it. visit vercel.com and open your project. Click the visit button and your website is live.

  5. to later update just use vercel --prod to push your code to production level.

Conclusion

So you see, it's that easy to upload your web app to the web for free in just 2 to 5 minutes. For this blog post, I have used the web template from this repo. If you want the complete code then visit

I have deployed the website to https://vercel-python-ten.vercel.app/ if you want to check out. I hope you liked my blog and if this article adds any value then it would be great if you leave a like and make sure to bookmark it as well. Also, share the post with your friends so that they too can learn something new(don't be selfish...). Also if possible you can follow me on twitter, so that we can discuss more about tech there. Hope to be in your mind again, till then b-bye!

bye bye

Other Articles

Socials

Top comments (12)

Collapse
 
thunderjaw09 profile image
thunderjaw

I have a question, when I tried to deploy the web app, the error "Error: The result of "builder.build" must include an output property for "@liudonghua123/now-flask"." appears. I've tried searching for a solution but to no avail. Do you have any solutions for this?

Collapse
 
yash_makan profile image
Yash Makan • Edited

Yes, I too faced this issue a while back and what i'll suggest you is to change the vercel.json to something like this... This will probaly solve the issue and will deploy smoothly... 😁
Do let me know if this works for you, then I'll add this in the blog article as well for future readers

{
  "version": 2,
  "builds": [
      {
          "src": "*.py",
          "use": "@vercel/python"
      }
  ],
  "routes": [
      {
          "src": "(.*)",
          "dest": "main.py"
      }
  ]
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
dooryan profile image
dooryan • Edited

hi. I also encountered the same problem when using "@liudonghua123/now-flask". I've tried using "@vercel/python" I only got this error: "Due to builds existing in your configuration file, the Build and Development Settings defined in your Project
Settings will not apply." ,and when I tried to preview I got this error:

This Serverless Function has crashed.
Your connection is working correctly.
Vercel is working correctly.
500: INTERNAL_SERVER_ERROR
Code: FUNCTION_INVOCATION_FAILED

how do I solve this?

Thread Thread
 
yash_makan profile image
Yash Makan

You can check the logs in vercel, this means that some error is encountered in python script. Also, if you are have app.run() in python script then also the app will not work. You have to remove app.run() as well. Moreover check the logs to find out the error...

Thread Thread
 
muditgupta68 profile image
Mudit Gupta

then apart from app.run() what should i write, should I comment it and then deploy? because I thought, app.run() initiates the running process of flask app. Do let me know.

Collapse
 
rimuwu profile image
AS1

delete Heroku....

Collapse
 
dilutewater profile image
Rachit Khurana • Edited
Collapse
 
yash_makan profile image
Yash Makan

Thanks for sharing! 😀

Collapse
 
dilutewater profile image
Rachit Khurana

I personally use heroku & qovery. One of my django site is on heroku and another one is on qovery.
They both are nice.
I have experienced database loss on qovery.
But heroku is much more reliable.

Collapse
 
katzkaa profile image
Katzkaa

hello I get this error when running the vercel command can u help me pls?

entrypoint is main.py
Error: Cannot convert undefined or null to object

Collapse
 
maahirvy profile image
maahir-vy

Command failed: /tmp/5184df82/bin/pip install -t /tmp/58dc369a -r /tmp/58dc369a/requirements.txt

what to do

Collapse
 
httpanand profile image
Anand

Replit ?🙂