How to Deploy a Python Flask App on Railway

A step-by-step guide to deploying a Python Flask app on Railway with Gunicorn, using a one-click starter template or your own code.

Flask is a lightweight Python web framework built on the Werkzeug WSGI toolkit and the Jinja2 template engine. It gives you routing and templates and leaves everything else to extensions, which makes it a popular choice for small apps and APIs. This guide deploys a minimal Flask app on Railway with one click, then shows how to deploy your own.

Deploy the Flask Starter on Railway

Deploy the one-click Flask template on Railway. There are no variables to set. Once the build finishes, open the generated xxx.up.railway.app URL. To use your own domain, see the last section of this post.

Deploy on Railway

What's in the Template

The starter repository is deliberately small:

  • main.py: the app and its one route
  • templates/index.html: the page that route renders
  • static/: CSS and the favicon
  • requirements.txt: Flask and Gunicorn, with pinned versions
  • .python-version: the Python version Railway installs
  • Procfile: the command that starts the app

The whole app is a few lines:

from flask import Flask, render_template

app = Flask(__name__)


@app.route("/")
def index():
    return render_template("index.html")


if __name__ == "__main__":
    app.run(port=5000)

Flask's built-in server, the app.run() line, is only for running the app on your own machine. On Railway, the Procfile starts the app with Gunicorn, a production WSGI server:

web: gunicorn main:app

Gunicorn listens on the PORT variable that Railway provides, so no port settings are needed.

To add a page, add a route to main.py and a matching template under templates/. Put CSS, JavaScript and images in static/ and link to them with url_for('static', filename='...').

Deploy Your Own Flask App

If your Flask app is already in a GitHub repository, create a new project in Railway, choose Deploy from GitHub repo and select your repository. Railway detects a Python app from requirements.txt, installs your dependencies and works out the start command. If Flask and Gunicorn are both in requirements.txt and your app object is app in main.py, it runs Gunicorn for you. Otherwise, add a Procfile like the one above, pointing at your module and app name, for example web: gunicorn app:app. Then go to Settings → Networking and click Generate Domain to get a public URL.

Frequently Asked Questions

Why does my app show "Application failed to respond"? Usually because the app is running on Flask's development server, which listens only on 127.0.0.1. Railway can't reach it there. Start it with Gunicorn instead, which listens on Railway's PORT.

Which Python version does Railway use? The version in a .python-version file, if you have one. Otherwise Railway uses its current default, Python 3.13.

Do I need Gunicorn? Yes, for anything public. Flask's built-in server is meant for local development only. Add gunicorn to requirements.txt.

Is Railway free for Flask apps? New accounts get a 30-day trial with a one-time $5 credit, then move to the Free plan with $1 of usage credit a month. That's enough for a small app like this one.

Subscribe to alphasec

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe