Skip to content

Instantly share code, notes, and snippets.

@tech-savvy-guy
Created December 21, 2022 04:03
Show Gist options
  • Save tech-savvy-guy/0dc7d3383ac3659e6db9e0a3bf536386 to your computer and use it in GitHub Desktop.
Save tech-savvy-guy/0dc7d3383ac3659e6db9e0a3bf536386 to your computer and use it in GitHub Desktop.
How to deploy a Python App on Railway

Deploy a Python App on Railway under 2 minutes!

Let's see how we can deploy a Flask Application to Railway:

Here we have a very simple Flask App:

import flask

app = flask.Flask(__name__)

@app.route('/')
def index():
    return "Hello World!"

if __name__ == '__main__':
    app.run()

We name this file main.py

We create two more files:

  • requirements.txt

    Flask
    gunicorn
    
  • Procfile

    web: gunicorn server:app
    

The directory should look like this:

├── src
│   ├── main.py
│   │
│   ├── Procfile
│   |
│   ├── requirements.txt

Now simply create a GitHub Repository and add the files that we just created.

Log in to your Railway dashboard and create a new project.

Choose Deploy from GitHub repo

After that, simply configure your GitHub settings to allow Railway to read the repository with your app.

And just like that you have deployed your Python App to Railway!

You can generate a domain for your app or even connect your custom domain!

Written by Soham Datta ✌🏻

@hotelbuddy-online
Copy link

i do exactly this and get no module named 'server' error

@hotelbuddy-online
Copy link

instead of web: gunicorn server:app
web: gunicorn main:app

works

@RajnishXCode
Copy link

the single route worked but when I added multiple routes, the Application failed to respond

@devashish2024
Copy link

I was also application failed to respond but it auto got fixed LEZ GO!

@RehanAdilAbbasiRAA
Copy link

where we can add templates. show this process

@volt-l18
Copy link

where we can add templates. show this process

make a folder name "templates" flask automatically will recognise this folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment