Deploying Python applications used to be hard. Not anymore. Render has become the go-to alternative to Heroku, offering a generous free tier that includes HTTPS, Git push-to-deploy, and custom domains. Here is exactly how to do it.
1. Prepare Your Project
Before you push code, you need two critical files in your project root so Render knows how to run your app.
Create requirements.txt
This file lists all the Python libraries your app needs (like Flask).
pip freeze > requirements.txt
Create Procfile
Create a file named literally Procfile (no extension) and add the following line. This tells Render to use Gunicorn (a production server) instead of the default Flask development server.
web: gunicorn app:app
Note: app:app means "look in app.py for the object named app".
2. Push to GitHub
Render connects directly to your GitHub repository. Commit your changes and push them.
git add .
git commit -m "Prepare for deployment"
git push origin main
3. Configure Render
- Log in to Render.com.
- Click New + and select Web Service.
- Connect your GitHub account and select your repository.
- Give your service a unique name (e.g.,
my-awesome-flask-app).
Ensure the following settings are correct:
| Runtime |
Python 3 |
| Build Command |
pip install -r requirements.txt |
| Start Command |
gunicorn app:app |
4. Environment Variables
Never commit secrets like API keys or your Flask SECRET_KEY to GitHub. Instead, add them to Render.
- Scroll down to the Environment Variables section.
- Add Key:
SECRET_KEY
- Add Value: (Generate a random string, or use our Password Generator)
5. Deploy!
Click Create Web Service. Render will start building your app. You can watch the logs in real-time. Once it says "Live", your app is online at https://your-app-name.onrender.com.
Congratulations! You are live.