How to deploy your Flask application to render.com for free

If you have a Flask application running locally, you can deploy it to render.com for free in just a few easy steps.

While an app hosted on render.com’s free plan comes with its limitations, it can be very useful for showcasing your hobby project on the web.

(I’m not sponsored by, or otherwise affiliated with, render.com in any way. I just found it to be a simple, easy, and free way to host my Flask web service I built as a hobby project and so wanted to share how deploying to it works.)

Have these first

Prerequisites to follow this guide and upload your app to render.com:

  • Python installed on your computer
  • A working Flask web application that runs on localhost
  • A free account on render.com
  • Git installed on your computer
  • A GitHub or GitLab account and a repository containing your Flask app

Generate a ‘requirements.txt‘ file

In order for render.com’s server to know which dependencies to install, define them in a file called ‘requirements.txt‘.

This file is analogous to package.json if you are coming to Python from the Node ecosystem (like I am).

What worked best for me was to use a package called pipreqs to generate this file. Since I used a virtual environment for developing my Flask application, as is recommended practice for Python applications, the pip freeze command didn’t work properly. Follow these steps to generate the requirements.txt file. Make sure you’re in the top-level directory for the project, because that’s where you want the requirements.txt file to be.

Add gunicorn to ‘requirements.txt

There’s a particular library that render.com will use to execute your Flask application, and it’s called gunicorn.

Add ‘Gunicorn‘ to your ‘requirements.txt‘ file, below the other dependencies that were generated in the file by using pipreqs.

Since this library is just being used as an HTTP server for render.com to run your application, no need to install it locally.

Once that’s done, commit that to your git repository and make sure that commit is in branch of your Github repository that you plan to deploy to render.com. The default branch for this is main.

Create a new Web Service in your Render.com dashboard

Go to render.com and login to your free account.

In the dashboard, click the purple ‘New +‘ button at the top of the screen. Select ‘Web Service‘ from the list of options.

Next, select the first option: ‘Build and deploy from a Git repository‘.

Follow the prompts to connect your GitHub or GitLab account to render.com.

Next, select the repository that holds your Flask application.

You will see a Settings form with some values already filled out. Make sure the Git branch you want to deploy is correct.

For the ‘Build command‘ setting, make sure the field says: pip install -r requirements.txt.

For the ‘Start command‘ setting, make sure the field says: gunicorn app:app.

Below this settings form, select the ‘Free‘ tier.

Click ‘Create Web Service‘ at the bottom of the form. Render will build and deploy your Flask app. If any errors arise in this step, they will be logged in your dashboard and you can use this error message to debug.

🎉 Celebrate 🎉

Your Flask app is now live with a render.com URL. You can now share it with colleagues or connect it to a frontend like a React app. Have fun building!