Deploy Flask

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

Deploy Flask

Just deployed

Deploy and Host Flask on Railway

Flask logo

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

ServicePurpose
ServerFlask 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

VariableRequiredDescription
PORTAuto-setRailway sets it; Gunicorn binds to it automatically.
FLASK_SECRET_KEY (your own)RecommendedAdd one if you use sessions, and read it in main.py.
DATABASE_URL, …OptionalAdd 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 RailwayHerokuRenderVercel
Monthly cost~$1–5 usage$5 Eco, $7 BasicFree (sleeps) or paidFree (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

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.


Template Content

More templates in this category

View Template
open-excalidraw
Self-hostable collaborative drawing built on Excalidraw

Prateek Mohanty
5
View Template
NEW
Next.js + Prisma + PostgreSQL Starter
Deploy a Next.js app with Prisma ORM and PostgreSQL in one click.

blueorange
0
View Template
caring-vibrancy
Deploy and Host caring-vibrancy with Railway

5