---
title: "Deploy Flask"
description: "Deploy a minimal Python Flask web app with Gunicorn and HTTPS in one click."
category: "Starters"
url: https://railway.com/deploy/flask-python-starter
---

# Deploy Flask

Deploy a minimal Python Flask web app with Gunicorn and HTTPS in one click.

**[Deploy Flask on Railway](https://railway.com/template/flask-python-starter)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/flask-python-starter/manifest.json

- **Creator:** blueorange
- **Category:** Starters

## Template content

### Server https://devicons.railway.app/i/flask-light.svg

- **Source:** https://github.com/alphasecio/flask
- **Public domain:** Yes

## Documentation

# Deploy and Host Flask on Railway

![Flask logo](https://raw.githubusercontent.com/pallets/flask/main/docs/_static/flask-name.svg)

Flask is the lightweight Python web framework with **74,000+ GitHub stars**, loved for starting small and growing into APIs and full apps. This template deploys a minimal Flask app served by Gunicorn, with HTTPS, on Railway in about a minute. Heroku's always-on dyno is $7/month — a small Flask app on Railway usually runs for a few dollars a month, and the code is yours to extend.

---

## What This Template Deploys

| Service | Purpose |
|---|---|
| **Server** | Flask app built from GitHub (`main.py` + `templates/`), served by Gunicorn via the `Procfile` (`web: gunicorn main:app`). Public HTTPS domain. |

One stateless service. Railway builds it from `requirements.txt` with Railpack — no Dockerfile needed. Add Postgres or Redis from the canvas when your app needs data.

---

## About Hosting Flask

`flask run` is a development server; production Flask needs a WSGI server like Gunicorn, a port the platform can route to, HTTPS and automatic redeploys. On a VPS that's a virtualenv, systemd unit, Nginx and Certbot.

On Railway, Gunicorn starts from the `Procfile`, binds to the port Railway provides, and every push to your fork redeploys automatically. Logs stream to the dashboard.

**It's a starter.** You get one route and one template to build from — no database, auth or background workers. The container filesystem resets on each deploy, so keep data in a database or a volume.

Typical cost: **~$1–5/month** in Railway usage for a small app, within the $5 Hobby plan. Heroku charges $5 for an Eco dyno that sleeps and $7 for one that stays up; Render's free tier spins down after 15 minutes idle.

---

## Deploy Flask in Under 2 Minutes

1. Click **Deploy on Railway** — Railway forks the code and installs Flask and Gunicorn (~1 minute).
2. Open the public URL to see the page.
3. Clone your repository and add routes to `main.py` and templates to `templates/`.
4. Add packages to `requirements.txt` and push — Railway rebuilds.
5. Attach Postgres from the canvas when you need a database.

No virtualenv on a server. No Nginx. No sleeping dyno.

---

## Common Use Cases

- **Heroku alternative for Python** — "deploy flask app" without dyno sleep
- **REST and JSON APIs** — add Flask routes or Flask-RESTX
- **ML model serving** — wrap a scikit-learn or PyTorch model in an endpoint
- **Webhooks and bots** — always-on endpoints for Slack, Stripe or Telegram
- **Small websites** — Jinja templates with a live URL
- **Teaching and prototypes** — Python web app online in minutes

---

## Configuration

| Variable | Required | Description |
|---|---|---|
| `PORT` | Auto-set | Railway sets it; Gunicorn binds to it automatically. |
| `FLASK_SECRET_KEY` (your own) | Recommended | Add one if you use sessions, and read it in `main.py`. |
| `DATABASE_URL`, … | Optional | Add when you attach a database, using Railway variable references. |

**Run Flask through Gunicorn, not `app.run`.** The `Procfile` already does this — if you change the start command, keep Gunicorn, or the app will run on Flask's development server.

---

## Flask on Railway vs. Alternatives

| | Flask on Railway | Heroku | Render | Vercel |
|---|---|---|---|---|
| **Monthly cost** | ~$1–5 usage | $5 Eco, $7 Basic | Free (sleeps) or paid | Free (non-commercial), $20 per seat Pro |
| **Always-on server** | ✅ Yes | ⚠️ Eco sleeps when idle | ⚠️ Free spins down | ❌ Serverless functions |
| **Long requests and background work** | ✅ Yes | ✅ Yes | ✅ Yes | ⚠️ Function time limits |
| **Database in the same project** | ✅ One click | ✅ Add-ons | ✅ Yes | ⚠️ Via marketplace |
| **Deploy on git push** | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
| **License** | ✅ BSD-3 Flask, starter code yours | ❌ Proprietary platform | ❌ Proprietary platform | ❌ Proprietary platform |

---

## Dependencies for Flask Hosting

- Railway account — Hobby ($5/month) covers a small app.
- A GitHub account — Railway forks the starter so you own the code.

### Deployment Dependencies

- [Flask](https://flask.palletsprojects.com/) — framework docs
- [Gunicorn](https://gunicorn.org/) — production WSGI server
- [Railpack](https://railpack.com/) — Railway's zero-config builder
- [Railway Docs](https://docs.railway.com/) — domains, variables and databases

### Implementation Details

Railpack detects `requirements.txt`, installs `flask` and `gunicorn`, and starts the `Procfile` command `gunicorn main:app`. Gunicorn picks up Railway's `PORT` automatically and serves the single route that renders `templates/index.html`.

The requirements are unpinned (`flask>=2.0.0`, `gunicorn>=20.1.0`); pin exact versions in your fork for repeatable builds.

---

## Frequently Asked Questions

**What does this Flask template include?**
A minimal Flask app with one route and a Jinja template, served by Gunicorn on a public HTTPS URL. It's a starting point you extend.

**How much does Flask hosting cost compared to Heroku?**
Usually $1–5/month of Railway usage, covered by the $5 Hobby plan. Heroku's Eco dyno is $5 and sleeps when idle; an always-on Basic dyno is $7.

**Why does my Flask app crash with "address already in use" or 502 errors?**
Don't call `app.run()` in production or hard-code a port — let Gunicorn bind to Railway's `PORT`, as the `Procfile` does.

**Do I lose data when I redeploy?**
Files written inside the container reset on each deploy. Use Railway Postgres or Redis for data, or mount a volume for files.

**Can I add a database or background jobs?**
Yes. Add Postgres or Redis from the Railway canvas and connect with variable references; run a worker (for example Celery or RQ) as a second service from the same repo.

**Can I use FastAPI or Django instead?**
Yes — change `requirements.txt` and the start command in your fork. Railpack builds most Python projects automatically.

---

## Why Deploy and Host Flask on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Flask on Railway, you get a Gunicorn-served Python app with HTTPS and git-push deploys for a few dollars a month, ready to grow into an API or full app.


## Similar templates

- [open-excalidraw](https://railway.com/deploy/open-excalidraw) — Self-hostable collaborative drawing built on Excalidraw
- [Next.js + Prisma + PostgreSQL Starter](https://railway.com/deploy/nextjs-prisma-postgres) — Deploy a Next.js app with Prisma ORM and PostgreSQL in one click.
- [caring-vibrancy](https://railway.com/deploy/caring-vibrancy) — Deploy and Host caring-vibrancy with Railway

Open this page in a browser: https://railway.com/deploy/flask-python-starter
